:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d7d2c6;
  --tile: #fffdf8;
  --tile-soft: #efe9dd;
  --tile-active: #f7d979;
  --tile-good: #67a36b;
  --tile-bad: #d46a5f;
  --black: #242424;
  --accent: #2f6f73;
  --accent-dark: #1e5558;
  --shadow: 0 18px 50px rgba(36, 36, 36, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  padding-bottom: 118px;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(47, 111, 115, 0.09), transparent 34%),
    radial-gradient(circle at right top, rgba(247, 217, 121, 0.22), transparent 28%),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 26px;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand img {
  flex: 0 0 auto;
  width: clamp(64px, 8vw, 96px);
  height: clamp(64px, 8vw, 96px);
  filter: drop-shadow(0 8px 14px rgba(31, 41, 51, 0.12));
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3.1rem, 7vw, 5.9rem);
  line-height: 0.94;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand p {
  color: var(--muted);
  font-size: 0.98rem;
  margin-top: 5px;
}

.stats-wrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.stats {
  display: grid;
  min-width: 96px;
  justify-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.74);
  box-shadow: 0 10px 28px rgba(36, 36, 36, 0.08);
}

.stats span:first-child {
  font-size: 1.55rem;
  font-weight: 800;
}

.stats span:last-child {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.account-button {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 58px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.78);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  box-shadow: 0 10px 28px rgba(36, 36, 36, 0.08);
}

.account-avatar,
#account-preview-avatar {
  display: grid;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 0.84rem;
  font-weight: 900;
  place-items: center;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 260px);
  gap: 12px;
  align-items: stretch;
}

.board-panel,
.side-panel,
.keyboard-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.82);
  box-shadow: var(--shadow);
}

.board-panel {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.board-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.board-tools button,
.puzzle-nav button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--tile);
  cursor: pointer;
}

.board-tools button:hover,
.puzzle-nav button:hover,
.word-button.can-open:hover,
.key:hover {
  border-color: var(--accent);
}

.board {
  --cols: 18;
  --rows: 13;
  --cell-size: min(38px, calc((100cqw - 8px - ((var(--cols) - 1) * 1px)) / var(--cols)));
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell-size));
  grid-auto-rows: var(--cell-size);
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  overflow: hidden;
  gap: 1px;
  padding: 1px;
  border: 2px solid #151515;
  border-radius: 2px;
  background: #151515;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  width: var(--cell-size);
  height: var(--cell-size);
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  background: #fffdf8;
  font-size: clamp(0.7rem, 2.5vw, 1.48rem);
  font-weight: 760;
  line-height: 1;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    background-color 140ms ease,
    box-shadow 140ms ease;
}

.cell.black {
  background: #1d1d1d;
  cursor: default;
}

.cell.locked {
  background: #eee8dc;
  color: var(--accent-dark);
}

.cell.cursor {
  background: #ffd957;
  box-shadow: inset 0 0 0 2px #111827;
}

.cell.cursor::after {
  position: absolute;
  right: 2px;
  bottom: 2px;
  display: grid;
  width: 13px;
  height: 13px;
  border-radius: 2px;
  background: #111827;
  color: white;
  content: "H";
  font-size: 0.58rem;
  font-weight: 900;
  line-height: 1;
  place-items: center;
}

.cell.cursor.down::after {
  content: "V";
}

.cell.correct {
  background: #dcebd6;
}

.cell.located {
  background: #cce7e4;
  color: #123f42;
}

.cell.wrong {
  background: #f5d2cd;
}

.cell.title-found {
  background: #cce7e4;
  color: #123f42;
}

.cell-letter {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.message {
  min-height: 26px;
  margin-top: 12px;
  color: var(--muted);
  font-weight: 650;
}

.puzzle-label {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 7px;
  margin: 0;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 750;
  text-transform: uppercase;
}

.puzzle-label strong {
  color: var(--accent-dark);
  font-size: clamp(1.7rem, 4vw, 2.45rem);
  line-height: 0.9;
}

.puzzle-label small {
  min-width: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.puzzle-direction {
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f1ede5;
  color: var(--accent-dark) !important;
}

.puzzle-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.puzzle-nav button {
  display: grid;
  width: 38px;
  padding: 0;
  place-items: center;
  font-size: 1.35rem;
  font-weight: 850;
}

.map-open-button {
  margin-left: auto;
  width: auto !important;
  min-width: 76px;
  font-size: 0.86rem !important;
  text-transform: uppercase;
}

.side-panel {
  display: flex;
  flex-direction: column;
  padding: 14px;
  min-height: 100%;
}

.word-panel h2 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.word-panel {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
}

.word-list {
  display: grid;
  gap: 14px;
  max-height: none;
  overflow: auto;
  padding-right: 4px;
}

.word-group h3 {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.word-group-items {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.word-button {
  min-height: 32px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tile);
  color: var(--ink);
  font-weight: 750;
  cursor: pointer;
}

.word-button:disabled {
  color: var(--ink);
  cursor: default;
  opacity: 1;
}

.word-button.done {
  border-color: #b7d3b0;
  background: #dcebd6;
  color: #244d28;
  text-decoration: line-through;
}

.keyboard-panel {
  position: fixed;
  right: 50%;
  bottom: 16px;
  z-index: 20;
  width: min(760px, calc(100% - 24px));
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  transform: translateX(50%);
}

.keyboard-panel.hidden {
  display: none;
}

.keyboard {
  display: grid;
  gap: 8px;
  padding: 0;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.key {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  width: clamp(28px, 7vw, 48px);
  height: clamp(42px, 8vw, 54px);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #e7e2d8;
  color: var(--ink);
  font-weight: 850;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.key.wide {
  width: clamp(64px, 14vw, 92px);
  font-size: 0.82rem;
}

.key.has-options::after {
  position: absolute;
  right: 4px;
  bottom: 3px;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: rgba(31, 41, 51, 0.38);
  content: "";
}

.accent-menu {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  display: flex;
  gap: 4px;
  padding: 5px;
  border: 1px solid rgba(215, 210, 198, 0.92);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 12px 30px rgba(36, 36, 36, 0.18);
  transform: translateX(-50%);
}

.accent-menu::after {
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 10px;
  height: 10px;
  background: rgba(255, 253, 248, 0.96);
  border-right: 1px solid rgba(215, 210, 198, 0.92);
  border-bottom: 1px solid rgba(215, 210, 198, 0.92);
  content: "";
  transform: translateX(-50%) rotate(45deg);
}

.accent-option {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 40px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f1ede5;
  color: var(--accent-dark);
  font-weight: 850;
  cursor: pointer;
}

.account-panel,
.puzzle-map-panel {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(31, 41, 51, 0.46);
}

.account-panel.hidden,
.puzzle-map-panel.hidden {
  display: none;
}

.account-card,
.puzzle-map-card {
  width: min(720px, 100%);
  max-height: min(720px, calc(100vh - 32px));
  overflow: auto;
  padding: 18px;
  border: 1px solid rgba(215, 210, 198, 0.96);
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: 0 24px 70px rgba(31, 41, 51, 0.28);
}

.account-card {
  width: min(420px, 100%);
}

.account-card-header,
.puzzle-map-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.account-card-header h2,
.puzzle-map-header h2 {
  font-size: 1.15rem;
}

.account-card-header p,
.puzzle-map-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.account-card-header button,
.puzzle-map-header button {
  display: grid;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tile);
  color: var(--ink);
  cursor: pointer;
  font-size: 1.4rem;
  font-weight: 800;
  place-items: center;
}

.account-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3efe7;
}

.account-card label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.account-card input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tile);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  text-transform: none;
  padding: 0 10px;
}

.account-actions {
  display: flex;
  gap: 8px;
}

.account-actions button {
  flex: 1;
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 850;
}

.account-actions .secondary {
  border-color: var(--line);
  background: var(--tile);
  color: var(--ink);
}

.hidden {
  display: none !important;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  text-transform: uppercase;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.map-legend i {
  display: block;
  width: 14px;
  height: 14px;
  border: 1px solid #b9b2a5;
  border-radius: 2px;
  background: #fffdf8;
}

.legend-started,
.puzzle-dot.started {
  border-color: #c59a22;
  background: #f7d979;
}

.legend-completed,
.puzzle-dot.completed {
  border-color: #5f955f;
  background: #84bd7f;
}

.puzzle-map-grid {
  display: grid;
  grid-template-columns: repeat(40, 1fr);
  gap: 5px;
}

.puzzle-dot {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  min-width: 0;
  padding: 0;
  border: 1px solid #b9b2a5;
  border-radius: 2px;
  background: #fffdf8;
  cursor: pointer;
}

.puzzle-dot:hover,
.puzzle-dot.current {
  border-color: #111827;
  box-shadow: 0 0 0 2px #111827;
}

@media (max-width: 700px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .board {
    --cell-size: min(36px, calc((100cqw - 8px - ((var(--cols) - 1) * 1px)) / var(--cols)));
  }

  .word-list {
    max-height: none;
  }

  .side-panel {
    min-height: auto;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 14px, 1180px);
    padding-top: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  .brand {
    align-items: flex-start;
  }

  .brand img {
    width: 56px;
    height: 56px;
  }

  h1 {
    font-size: clamp(2.55rem, 13vw, 4rem);
  }

  .brand p {
    max-width: 230px;
  }

  .stats {
    min-width: 78px;
    padding: 8px;
  }

  .stats-wrap {
    justify-content: flex-start;
  }

  .board-panel,
  .side-panel {
    padding: 10px;
  }

  .puzzle-nav {
    flex-wrap: wrap;
  }

  .board {
    gap: 1px;
    padding: 1px;
  }

  .key-row {
    gap: 4px;
  }

  .puzzle-label {
    flex: 1 1 100%;
    order: 3;
  }

  .map-open-button {
    margin-left: 0;
  }

  .puzzle-map-grid {
    grid-template-columns: repeat(25, 1fr);
    gap: 4px;
  }

}
