:root {
  color-scheme: light;
  --background: #f8f5ef;
  --surface: #ffffff;
  --text: #27313f;
  --muted: #657080;
  --line: #cfd7df;
  --accent: #287c7a;
  --accent-strong: #1f5f5d;
  --selected: #6fd5c8;
  --clue: #354052;
  --clue-text: #ffffff;
  --board-max: 296px;
  --cell-font-size: 1rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

button,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(230px, 310px) minmax(320px, 760px);
  gap: 22px;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1 {
  margin: 0;
  color: var(--accent-strong);
  font-size: 2.2rem;
  font-weight: 500;
}

.language-picker {
  min-width: 150px;
}

.left-panel,
.game-area {
  min-width: 0;
}

.left-panel {
  display: grid;
  align-content: start;
  gap: 12px;
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
}

.rules-box,
.about-box,
.control-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
}

.rules-box summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 10px;
  color: var(--accent-strong);
  font-size: 1.15rem;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}

.rules-box summary::-webkit-details-marker {
  display: none;
}

.rules-box summary::after {
  content: "";
  width: 9px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 160ms ease;
}

.rules-box[open] summary::after {
  transform: rotate(225deg) translateY(-2px);
}

.rules-content p,
.rules-box li,
.quick-controls p {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.rules-content p {
  margin: 0 0 10px;
}

.rules-box ul {
  margin: 0;
  padding-left: 18px;
}

.rules-box li + li {
  margin-top: 7px;
}

.about-box h2 {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 1.05rem;
  font-weight: 500;
}

.about-box p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.support-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.support-links a {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--accent-strong);
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
}

.support-links .support-icon {
  display: block;
  width: 13px;
  max-width: 13px;
  height: 13px;
  max-height: 13px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
  opacity: 0.72;
  overflow: hidden;
}

.support-links .support-icon--brand {
  fill: currentColor;
  stroke: none;
  opacity: 0.68;
}

.support-links span {
  min-width: 0;
}

.support-links a:hover {
  border-color: var(--accent);
  background: #eef6f5;
}

.game-area {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.control-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(160px, 0.95fr) minmax(140px, 0.8fr);
  gap: 12px;
  align-items: end;
}

.control-group {
  display: grid;
  gap: 10px;
}

.random-controls {
  grid-template-columns: minmax(0, 1fr);
}

.quick-controls p {
  min-height: 22px;
  margin: 0;
  text-align: center;
}

.session-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 62px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.92rem;
}

select,
button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
}

select {
  width: 100%;
}

button {
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

#loadRandomBtn,
#loadDailyBtn,
#tutorialBtn {
  width: 100%;
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

#hintsToggle {
  width: 100%;
}

#hintsToggle[aria-pressed="true"] {
  border-color: var(--accent);
  background: #eef6f5;
}

#colorModeBtn[aria-pressed="true"],
#annotationModeBtn[aria-pressed="true"] {
  border-color: var(--accent);
  background: #eef6f5;
  color: var(--accent-strong);
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.mode-switch button {
  min-width: 116px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
}

.mode-switch button + button {
  border-left: 1px solid var(--line);
}

.timer-box {
  min-width: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 8px 14px;
  text-align: center;
}

.timer-box[hidden] {
  display: none;
}

.timer-box span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.timer-box strong {
  display: block;
  margin-top: 2px;
  font-size: 1.45rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.board-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
  padding: 10px 0 4px;
  overflow: hidden;
}

.grid {
  --rows: 5;
  --cols: 5;
  --board-max: 296px;
  width: min(100%, var(--board-max));
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 2px;
  background: var(--line);
  border: 2px solid var(--line);
  border-radius: 8px;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.grid.is-complete {
  transform: scale(1.01);
  border-color: var(--accent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--selected) 30%, transparent);
}

.cell {
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  border: 0;
  border-radius: 0;
  padding: 0;
  font-size: var(--cell-font-size);
  font-weight: 500;
}

.cell.clue {
  background: var(--clue);
  color: var(--clue-text);
  cursor: default;
}

.cell.playable {
  background: var(--surface);
}

.cell.playable:hover {
  background: #eef6f5;
}

.cell.selected {
  background: var(--selected);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 36%, transparent);
}

.cell.playable.selected:hover {
  background: var(--selected);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.cell.annotated {
  position: relative;
}

.cell.annotated::before,
.cell.annotated::after {
  content: "";
  position: absolute;
  width: 70%;
  height: 2px;
  border-radius: 999px;
  background: rgba(180, 74, 66, 0.58);
}

.cell.annotated::before {
  transform: rotate(45deg);
}

.cell.annotated::after {
  transform: rotate(-45deg);
}

.cell.hint-over {
  box-shadow: inset 0 0 0 3px #b44a42;
}

.cell.hint-block {
  background: #f2b8b1;
}

.cell.selected.hint-block {
  background: #e99a92;
}

.status {
  min-height: 28px;
  margin: 0;
  color: var(--accent-strong);
  font-weight: 500;
  text-align: center;
}

.share-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 0;
}

.share-dialog::backdrop {
  background:
    linear-gradient(115deg, rgba(255, 255, 255, 0) 18%, rgba(255, 255, 255, 0.34) 42%, rgba(255, 255, 255, 0) 62%),
    radial-gradient(circle at 24% 18%, rgba(111, 213, 200, 0.24), transparent 32%),
    rgba(39, 49, 63, 0.34);
  backdrop-filter: blur(5px) saturate(1.08);
}

.share-dialog__panel {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 24px;
  box-shadow: 0 24px 60px rgba(39, 49, 63, 0.18);
}

.share-dialog__panel h2 {
  margin: 0 0 18px;
  color: var(--accent-strong);
  font-size: 1.45rem;
  font-weight: 500;
  text-align: center;
}

.share-dialog__close {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  width: 34px;
  min-height: 34px;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
}

.share-summary {
  display: grid;
  gap: 10px;
  margin: 0 0 18px;
}

.share-summary div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.share-summary dt {
  color: var(--muted);
  font-size: 0.92rem;
}

.share-summary dd {
  margin: 0;
  color: var(--text);
  font-size: 1.08rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.share-copy {
  width: 100%;
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    padding: 18px;
  }

  .topbar {
    order: 1;
  }

  .game-area {
    order: 2;
  }

  .left-panel {
    order: 3;
    position: static;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 720px) {
  .control-panel {
    grid-template-columns: minmax(0, 1fr);
  }

  .random-controls {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 520px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .language-picker,
  .session-bar button {
    width: 100%;
  }

  .session-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(100px, auto);
    gap: 8px;
  }

  .timer-box {
    min-width: 0;
  }

  .mode-switch {
    grid-column: 1 / -1;
    width: 100%;
  }

  .mode-switch button {
    min-width: 0;
    width: auto;
  }

  #shareResultBtn {
    grid-column: 1 / -1;
  }

  .share-dialog {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
  }

  .share-dialog__panel {
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 8px 8px 0 0;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding: 12px;
  }

  .rules-box,
  .about-box,
  .control-panel {
    padding: 12px;
  }

  .share-dialog__panel {
    padding: 20px 16px;
  }

  .share-summary div {
    display: grid;
    gap: 4px;
  }

  .share-summary dd {
    text-align: left;
  }
}

@media (max-width: 340px) {
  .session-bar {
    grid-template-columns: minmax(0, 1fr);
  }
}
