:root {
  --bg: #f3efe6;
  --ink: #202124;
  --muted: #67655e;
  --line: #2d2d31;
  --panel: #fffdf7;
  --accent: #206c7a;
  --accent-strong: #154d58;
  --bad: #9d2f2f;
  --good: #24704f;
  --cell: 64px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
  background:
    linear-gradient(120deg, rgba(32, 108, 122, .12), transparent 40%),
    linear-gradient(300deg, rgba(178, 72, 58, .13), transparent 45%),
    var(--bg);
}

button, select {
  font: inherit;
}

.app {
  width: min(1320px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 28px 0;
}

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

.top-actions {
  display: flex;
  align-items: end;
  gap: 12px;
}

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

.tabs button {
  min-height: 44px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.tabs button.active {
  background: var(--accent);
  color: white;
}

.help-button, .share-button {
  display: grid;
  place-items: center;
  height: 44px;
  border: 2px solid var(--line);
  background: var(--panel);
  color: var(--accent-strong);
  font-weight: 950;
  cursor: pointer;
}

.help-button {
  width: 44px;
  border-radius: 50%;
}

.share-button {
  min-width: 78px;
  padding: 0 14px;
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(36px, 5vw, 68px);
  line-height: 1;
}

h2 {
  font-size: 21px;
  margin-bottom: 12px;
}

.progress {
  min-width: 90px;
  padding: 13px 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: center;
  font-weight: 800;
}

.playfield {
  display: grid;
  grid-template-columns: 290px minmax(390px, 1fr) 270px;
  gap: 20px;
  align-items: start;
}

.panel {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, .88);
  box-shadow: 0 8px 0 rgba(32, 33, 36, .12);
  padding: 18px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.intro, .hint, .message {
  color: var(--muted);
  line-height: 1.45;
}

.hint {
  margin: 12px 0 0;
  color: var(--accent-strong);
  font-weight: 650;
}

.shape-list {
  display: grid;
  gap: 12px;
}

.shape-card {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 10px;
  align-items: center;
  border-top: 1px solid rgba(45, 45, 49, .2);
  padding-top: 12px;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(var(--w), 14px);
  grid-template-rows: repeat(var(--h), 14px);
  gap: 2px;
}

.mini-cell {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: transparent;
}

.mini-cell.on {
  border: 1px solid var(--line);
  background: var(--accent);
}

.shape-name {
  margin: 0;
  font-weight: 800;
}

.shape-rule {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.board-wrap {
  min-width: 0;
}

.board {
  --cols: 6;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  justify-content: center;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  border: 4px solid var(--line);
  border-radius: 8px;
  background: #1f2025;
  overflow: hidden;
  touch-action: none;
}

.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  border: 2px solid rgba(31, 32, 37, .75);
  background:
    linear-gradient(135deg, rgba(255,255,255,.35), transparent 45%),
    var(--fill, #e7e0d2);
  cursor: pointer;
}

.cell.block {
  cursor: default;
  background:
    repeating-linear-gradient(45deg, #22252c 0 7px, #30343c 7px 14px);
}

.cell.bad {
  box-shadow: inset 0 0 0 4px var(--bad);
}

.cell.good {
  box-shadow: inset 0 0 0 4px var(--good);
}

.cell.locked {
  cursor: default;
  box-shadow:
    inset 0 0 0 4px rgba(255, 255, 255, .75),
    inset 0 0 0 8px rgba(32, 33, 36, .34);
}

.cell.locked::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 3px solid rgba(32, 33, 36, .45);
  border-radius: 7px;
  pointer-events: none;
}

.mark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(32, 33, 36, .82);
  font-weight: 900;
  font-size: 22px;
  pointer-events: none;
}

.tools {
  display: grid;
  gap: 14px;
  overflow: hidden;
}

.tools-head {
  justify-content: center;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(45, 45, 49, .18);
}

.tools h2 {
  margin: 0;
}

.current-tool {
  display: grid;
  gap: 9px;
  justify-items: center;
}

.current-tool p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.current-color, .icon-btn, .level-nav button {
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.current-color {
  width: min(100%, 156px);
  aspect-ratio: 1;
  height: auto;
  cursor: default;
  background:
    linear-gradient(135deg, rgba(255,255,255,.45), transparent 48%),
    var(--current);
  box-shadow: inset 0 0 0 8px rgba(255,255,255,.28);
}

.icon-btn:focus-visible, button:focus-visible, select:focus-visible {
  outline: 3px solid rgba(32, 108, 122, .45);
  outline-offset: 2px;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.tools button,
.tools select {
  width: 100%;
  min-width: 0;
}

.actions button, .level-nav select {
  min-height: 48px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.actions .primary {
  grid-column: 1 / -1;
  background: var(--accent);
  color: white;
  font-weight: 900;
}

.level-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 48px));
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.level-select-hidden {
  display: none;
}

.level-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
  max-height: 190px;
  overflow-y: auto;
  margin-top: 12px;
  padding-right: 3px;
}

.level-chip {
  min-height: 38px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.level-chip.done {
  background: #dff1e8;
}

.level-chip.current {
  background: var(--accent);
  color: white;
}

.level-chip.locked {
  opacity: .44;
  cursor: not-allowed;
}

.daily-tools {
  border-top: 1px solid rgba(45, 45, 49, .2);
  padding-top: 14px;
}

.daily-date {
  margin: 0 0 10px;
  font-weight: 800;
  text-align: center;
}

.daily-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.daily-stat {
  display: grid;
  gap: 4px;
  min-height: 62px;
  margin: 0;
  place-items: center;
  border: 2px solid rgba(45, 45, 49, .22);
  border-radius: 8px;
  background: rgba(255, 253, 247, .62);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.daily-stat strong {
  color: var(--ink);
  font-size: 15px;
  text-transform: none;
}

.daily-stat.wide {
  grid-column: 1 / -1;
}

.message {
  min-height: 48px;
  margin: 14px auto 0;
  max-width: 680px;
  text-align: center;
  font-weight: 700;
}

.message.ok {
  color: var(--good);
}

.message.err {
  color: var(--bad);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 21, 24, .42);
  z-index: 20;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(430px, 100%);
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 0 rgba(32, 33, 36, .22);
  padding: 22px;
}

.modal-card h2 {
  font-size: 32px;
}

.modal-card button {
  min-height: 46px;
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 900;
  cursor: pointer;
}

@media (max-width: 900px) {
  :root {
    --cell: min(12.6vw, 48px);
  }

  .playfield {
    grid-template-columns: 1fr;
  }

  .topbar, .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .tools {
    order: -1;
  }
}
