* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  height: 100%;
  background: #f4f6f8;
  color: #1c2430;
  font-family: "Segoe UI", system-ui, sans-serif;
}

body {
  padding:
    calc(env(safe-area-inset-top) + 8px)
    12px
    calc(env(safe-area-inset-bottom) + 10px);
}

main {
  max-width: 560px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mark {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1c2430;
}

.spoken {
  margin: 4px 0 0;
  min-height: 1.3em;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: #1f4e79;
}

.stage {
  position: relative;
  width: 86px;
  height: 64px;
  flex: 0 0 auto;
  border-radius: 8px;
  overflow: hidden;
  background: #1c2430;
  border: 1px solid #1c2430;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #000;
}

.presence {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 2px 4px;
  background: rgba(28, 36, 48, 0.82);
  color: #fff;
  font-size: 0.68rem;
  text-align: center;
}

.board {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 12px;
}

.tile {
  min-height: 0;
  border-radius: 10px;
  border: 2px solid #1c2430;
  background: #fff;
  color: #1c2430;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  transform: scale(1);
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.pic {
  font-size: clamp(1.6rem, 6vh, 2.4rem);
  line-height: 1;
  color: #1c2430;
}

.pic.icon svg {
  width: clamp(2rem, 7vh, 3rem);
  height: clamp(2rem, 7vh, 3rem);
  display: block;
}

.pic.photo {
  width: 46%;
  height: 46%;
  object-fit: contain;
  font-size: 0;
}

.word {
  font-size: clamp(1.15rem, 2.8vh, 1.5rem);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.tile.hot {
  transform: scale(1.03);
  border-color: #1f4e79;
  border-width: 3px;
  box-shadow: inset 0 0 0 2px #1f4e79;
}

.tile.picked {
  transform: scale(1.06);
  background: #1f4e79;
  color: #fff;
  border-color: #1f4e79;
  z-index: 1;
}

.tile.picked .pic {
  color: #fff;
}

.hint, .message {
  margin: 0;
}

.privacy-note {
  margin: 0;
  color: #1c2430;
  font-size: 0.98rem;
  line-height: 1.35;
  font-weight: 600;
}

.feel-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.feel-row button.on {
  background: #1f4e79;
  color: #fff;
  border-color: #1f4e79;
}

.message {
  min-height: 1.2em;
  color: #1f4e79;
  font-size: 1rem;
  font-weight: 600;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

button {
  font: inherit;
  font-size: 1.05rem;
  min-height: 52px;
  border-radius: 8px;
  border: 1px solid #1c2430;
  padding: 8px 12px;
  background: #fff;
  color: #1c2430;
}

button.stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 68px;
}

.btn-name {
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.2;
}

.btn-note {
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.25;
  color: #1c2430;
}

#start {
  background: #1f4e79;
  color: #fff;
  border-color: #1f4e79;
  font-weight: 700;
}

.spell-word {
  margin: 0;
  min-height: 1.3em;
  text-align: center;
  font-size: clamp(1.7rem, 5vh, 2.6rem);
  font-weight: 800;
  letter-spacing: 0.12em;
}

.spell-word.empty {
  color: #1c2430;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0;
}

.tile .main {
  font-size: clamp(1.5rem, 4vh, 2.2rem);
  font-weight: 800;
  line-height: 1;
}

.tile.group .main {
  font-size: clamp(0.95rem, 2.5vh, 1.3rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-align: center;
  line-height: 1.25;
}

.tile.letter .main {
  font-size: clamp(2rem, 7vh, 3.2rem);
  font-weight: 800;
}

.tile .sub {
  font-size: 0.9rem;
  color: #1c2430;
  text-align: center;
}

.tile.picked .sub {
  color: #fff;
}

.settings {
  position: fixed;
  inset: 0;
  z-index: 5;
  overflow: auto;
  background: #f4f6f8;
  padding:
    calc(env(safe-area-inset-top) + 12px)
    12px
    calc(env(safe-area-inset-bottom) + 16px);
}

.settings-card {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #f4f6f8;
}

.settings-head, .blink-row, .edit-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.settings h1, .settings h2, .settings p {
  margin: 0;
}

.settings h1 { font-size: 1.6rem; }
.settings h2 { font-size: 1.05rem; margin-bottom: 8px; }

.blink-value {
  color: #1c2430;
  font-size: 1.8rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0;
}

.blink-row button, #addTile, #settingsClose, .delete {
  min-height: 48px;
}

#settingsClose,
#helpClose {
  background: #1f4e79;
  color: #fff;
  border-color: #1f4e79;
  font-weight: 700;
  min-width: 96px;
}

.edit {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  margin-bottom: 10px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #1c2430;
}

.edit label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.95rem;
  color: #1c2430;
}

.edit input[type="text"] {
  font: inherit;
  font-size: 1.05rem;
  color: #1c2430;
  background: #fff;
  border: 1px solid #1c2430;
  border-radius: 8px;
  min-height: 44px;
  padding: 0 10px;
}

.edit-pic {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #1c2430;
  color: #1c2430;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  overflow: hidden;
  flex: 0 0 auto;
}

.preview svg {
  width: 32px;
  height: 32px;
}

.preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid #1c2430;
  color: #1c2430;
  background: #fff;
}

#addTile { width: 100%; }

button:disabled {
  opacity: 1;
  background: #e8edf2;
  color: #1c2430;
}

#helpBtn {
  grid-column: 1 / -1;
}

.manual-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border-radius: 8px;
  border: 1px solid #1c2430;
  color: #1c2430;
  background: #fff;
  text-decoration: none;
  font-weight: 700;
}

.help-q {
  width: 100%;
  margin-top: 8px;
  text-align: left;
  background: #fff;
  color: #1c2430;
  border: 1px solid #1c2430;
}

.help-q.on {
  border-color: #1f4e79;
  color: #1f4e79;
}

.help-answer {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.35;
  font-weight: 700;
}

body.manual main {
  height: auto;
  padding-bottom: 24px;
}

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.steps li {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.steps h2 {
  margin: 0;
  font-size: 1.25rem;
}

.steps p {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.4;
}

.steps img {
  width: 100%;
  border-radius: 16px;
  border: 1px solid #1c2430;
}

.back {
  color: #1f4e79;
  font-weight: 700;
}

@media (max-height: 560px) {
  body {
    padding: 6px 8px;
  }

  main {
    gap: 4px;
  }

  .mark {
    font-size: 1rem;
  }

  .spoken {
    font-size: 1.05rem;
  }

  .stage {
    width: 64px;
    height: 48px;
  }

  .hint,
  .message {
    font-size: 0.75rem;
  }

  .board {
    gap: 6px;
  }

  .pic {
    font-size: clamp(1.35rem, 14vh, 2.2rem);
  }

  .word {
    font-size: clamp(0.78rem, 3.2vh, 1.05rem);
  }

  button {
    min-height: 36px;
    font-size: 0.9rem;
  }
}

@media (max-height: 560px) and (min-width: 700px) {
  .actions {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-height: 420px) {
  .btn-note {
    font-size: 0.8rem;
  }

  .stage {
    width: 52px;
    height: 40px;
  }

  button {
    min-height: 32px;
    font-size: 0.8rem;
  }
}
