:root {
  color-scheme: light;
  --ink: #776e65;
  --paper: #faf8ef;
  --board: #bbada0;
  --chip: #eee4da;
  --button: #8f7a66;
  --button-ink: #f9f6f2;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Roboto, "Segoe UI", sans-serif;
}

button { font: inherit; }

.app {
  width: min(100%, 640px);
  margin: 0 auto;
  padding:
    calc(10px + env(safe-area-inset-top))
    12px
    calc(18px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.1;
  font-weight: 800;
}

.tagline {
  display: none;
  margin: 4px 0 0;
  color: #a09486;
}

.scores { display: flex; gap: 8px; }

.score {
  min-width: 72px;
  background: var(--board);
  color: var(--button-ink);
  border-radius: 8px;
  text-align: center;
  padding: 6px 10px 8px;
}

.score span {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 700;
}

.score strong {
  display: block;
  font-size: 1.35rem;
  line-height: 1.1;
}

.score.record {
  background: #edc850;
  color: #3d3010;
}

#shuffle:disabled { opacity: 0.45; }

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.pill {
  border-radius: 999px;
  min-height: 42px;
  padding: 8px 8px;
  font-weight: 700;
  font-size: 0.78rem;
  line-height: 1.15;
  white-space: normal;
  border: 1px solid #d8cfc6;
  background: #fffdf8;
  color: var(--ink);
}

.pill.is-on {
  background: var(--button);
  border-color: var(--button);
  color: var(--button-ink);
}

.status,
.banner {
  border-radius: 8px;
  padding: 8px 12px;
  margin: 0 0 10px;
}

.status { background: var(--chip); }

.banner {
  background: #edc850;
  color: #3d3010;
  font-weight: 700;
}

.banner.hint { background: #f8efd4; font-weight: 600; }

.banner.over { background: #f2b179; }

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  background: var(--board);
  padding: 8px;
  border-radius: 12px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 700;
  font-size: clamp(0.68rem, 2.7vw, 0.95rem);
  line-height: 1.12;
  padding: 4px;
  min-width: 0;
}

.cell span { overflow-wrap: anywhere; }

.cell-empty { background: rgba(238, 228, 218, 0.55); }

.tile-subject { background: #6a96c8; color: #10233f; }
.tile-verb { background: #e4ad78; color: #3d2410; }
.tile-adverb { background: #c4a6d4; color: #2d143f; }
.tile-aux { background: #78b7ae; color: #10312e; }
.tile-object { background: #8fb584; color: #143018; }
.tile-clause { background: #e3c15a; color: #3d3010; font-size: clamp(0.62rem, 2.4vw, 0.82rem); }
.tile-sentence { background: #e07a5f; color: #fff; font-size: clamp(0.58rem, 2.2vw, 0.78rem); }

.tile-new { animation: pop 0.14s ease; }

@keyframes pop {
  from { transform: scale(0.82); }
  to { transform: scale(1); }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 8px 0 0;
}

.legend span,
.formula .chip {
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 700;
}

.swipe-hint {
  margin: 10px 0 0;
  text-align: center;
  color: #a09486;
  font-size: 0.85rem;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.actions button,
#install {
  background: transparent;
  color: var(--button);
  border: 2px solid var(--board);
  border-radius: 10px;
  min-height: 44px;
  font-weight: 700;
}

.install {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fffdf8;
  border: 1px solid #e4d8cc;
}

.install p { margin: 0 0 8px; }

#install { width: 100%; background: var(--button); color: var(--button-ink); border-color: var(--button); }

#install[hidden] { display: none; }

.handbook {
  margin-top: 14px;
  background: var(--chip);
  border-radius: 12px;
  padding: 4px 14px 12px;
}

.handbook summary {
  cursor: pointer;
  font-weight: 800;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.handbook p { margin: 8px 0; white-space: pre-wrap; }

.formula {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 6px 0;
}

.formula .plus { font-weight: 800; }

.scheme { margin-top: 12px; }

.scheme h2 {
  margin: 0;
  font-size: 1rem;
}

@media (min-width: 900px) and (min-height: 700px) {
  .app { padding-top: 28px; }
  h1 { font-size: 2.5rem; }
  .tagline { display: block; }
  .score strong { font-size: 1.55rem; }
  .modes-four { grid-template-columns: repeat(4, 1fr); }
  .board { gap: 10px; padding: 10px; max-width: 520px; margin: 0 auto; }
  .cell { font-size: 0.95rem; }
  .tile-clause { font-size: 0.82rem; }
  .tile-sentence { font-size: 0.78rem; }
  .phone-only { display: none; }
}
