:root {
  --bg: #f4efe6;
  --panel: #fffdf8;
  --ink: #192324;
  --muted: #6a7372;
  --line: #d8d2c7;
  --tile: #ffffff;
  --tile-border: #cfc8bb;
  --accent: #2f6f68;
  --accent-soft: #d8ebe7;
  --good: #3f7d54;
  --bad: #b6534b;
  --shadow: 0 18px 50px rgba(31, 39, 38, 0.1);
  --tile-size: clamp(48px, 14vw, 72px);
  --gap: clamp(7px, 2vw, 11px);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(47, 111, 104, 0.08), transparent 34rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

button { font: inherit; }
button:focus-visible { outline: 3px solid rgba(47, 111, 104, 0.35); outline-offset: 3px; }

.app {
  width: min(100%, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0 18px;
  border-bottom: 1px solid rgba(25, 35, 36, 0.11);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(47, 111, 104, 0.22);
  font-size: 20px;
  font-weight: 900;
}

h1 { margin: 0; font-size: clamp(20px, 5vw, 28px); line-height: 1.05; letter-spacing: -0.035em; }
.subtitle { margin-top: 4px; color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 8px; }

.icon-btn, .text-btn {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.65);
  cursor: pointer;
}

.icon-btn { width: 40px; display: grid; place-items: center; font-weight: 800; }
.text-btn { padding: 0 13px; font-weight: 700; }
.icon-btn:hover, .text-btn:hover { background: #fff; }

main { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 30px 0 10px; }

.topline {
  width: min(100%, 440px);
  display: flex;
  justify-content: space-between;
  align-items: end;
  margin-bottom: 15px;
}

.kicker, .found-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.progress-text { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }

.progress {
  width: min(100%, 440px);
  height: 7px;
  margin-bottom: 21px;
  border-radius: 99px;
  overflow: hidden;
  background: #e1dbd0;
}

.progress > span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.35s ease;
}

.board-wrap {
  position: relative;
  padding: clamp(10px, 3vw, 15px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.5);
  box-shadow: var(--shadow);
}

.board {
  display: grid;
  grid-template-columns: repeat(5, var(--tile-size));
  grid-template-rows: repeat(5, var(--tile-size));
  gap: var(--gap);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--tile-size);
  height: var(--tile-size);
  padding: 0;
  appearance: none;
  border: 1px solid var(--tile-border);
  border-radius: 17px;
  color: var(--ink);
  background: var(--tile);
  box-shadow: 0 5px 13px rgba(38, 45, 43, 0.055);
  font-size: clamp(23px, 7vw, 35px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  cursor: crosshair;
  transition: transform 0.12s ease, background-color 0.14s ease, color 0.14s ease,
    border-color 0.14s ease, box-shadow 0.14s ease;
}

.tile.selected {
  border-color: var(--accent);
  color: #173b37;
  background: var(--accent-soft);
  box-shadow: 0 3px 8px rgba(47, 111, 104, 0.15);
  transform: scale(0.97);
}

.tile.correct { border-color: var(--good); color: #245331; background: #dcecdf; animation: pop 0.32s ease both; }
.tile.wrong { border-color: var(--bad); color: #7f312b; background: #f4deda; animation: shake 0.32s ease both; }
.tile.new { animation: drop-in 0.42s cubic-bezier(0.2, 0.75, 0.28, 1.12) both; animation-delay: var(--delay, 0ms); }
.tile.settle { animation: settle 0.32s ease both; }

@keyframes pop { 50% { transform: scale(1.06); } }
@keyframes shake { 25% { transform: translateX(-4px); } 50% { transform: translateX(4px); } 75% { transform: translateX(-2px); } }
@keyframes drop-in {
  from { opacity: 0.25; transform: translateY(calc(-1 * var(--drop, 72px))) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes settle { from { transform: translateY(-10px); } to { transform: translateY(0); } }

.status {
  width: min(100%, 440px);
  min-height: 54px;
  padding: 14px 12px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
  line-height: 1.45;
}

.found-panel { width: min(100%, 440px); margin-top: 14px; }
.found-label { margin-bottom: 9px; }
.found-words { min-height: 32px; display: flex; flex-wrap: wrap; gap: 7px; }

.chip {
  padding: 6px 9px;
  border-radius: 9px;
  color: #4f5958;
  background: #e6e0d6;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.chip.latest { color: #fff; background: var(--accent); animation: chip-in 0.25s ease both; }
@keyframes chip-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

footer { padding-top: 16px; color: var(--muted); text-align: center; font-size: 11px; }

.overlay {
  position: fixed;
  z-index: 10;
  inset: 0;
  padding: 20px;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  background: rgba(18, 25, 25, 0.45);
  backdrop-filter: blur(4px);
  transition: opacity 0.2s ease;
}

.overlay.show { opacity: 1; pointer-events: auto; }

.dialog {
  width: min(100%, 440px);
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.2);
  transform: translateY(8px) scale(0.985);
  transition: transform 0.2s ease;
}

.overlay.show .dialog { transform: none; }
.dialog h2 { margin: 0 0 9px; font-size: 27px; letter-spacing: -0.035em; }
.dialog p { margin: 0 0 14px; color: var(--muted); line-height: 1.55; }
.dialog ul { padding-left: 20px; color: #4f5958; line-height: 1.55; }

.dialog .primary, .dialog .secondary {
  width: 100%;
  border-radius: 13px;
  padding: 12px 16px;
  font-weight: 800;
  cursor: pointer;
}

.dialog .primary { margin-top: 8px; border: 0; color: #fff; background: var(--accent); }
.dialog .secondary { margin-top: 8px; border: 1px solid var(--line); color: var(--ink); background: #fff; }
.score { display: flex; gap: 8px; margin: 18px 0 7px; }
.score span { flex: 1; padding: 10px 5px; border-radius: 12px; background: #eee8dd; text-align: center; font-weight: 900; }
.small { font-size: 12px; }

@media (max-width: 430px) {
  .app { padding-left: 12px; padding-right: 12px; }
  header { padding-bottom: 14px; }
  .text-btn { padding: 0 10px; }
  .subtitle { display: none; }
  main { padding-top: 22px; }
  .tile { border-radius: 14px; }
  .board-wrap { border-radius: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
