:root {
  --bg: #fff7ea;
  --ink: #172125;
  --card: #fffdf8;
  --line: #2b3840;
  --shadow: rgba(0, 0, 0, 0.12);
  --board-render-width: min(80vw, 690px, calc((100vh - 300px) * 1.14));
  --board-shell-width: calc(var(--board-render-width) + 0.8rem + 4px);

  --red: #d94037;
  --blue: #2763d8;
  --yellow: #f0c419;
  --purple: #b45be7;
  --green: #1fb85f;
  --orange: #f68b2d;
  --white: #ffffff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 700px at 10% -10%, #ffe9bb 10%, transparent 55%),
    radial-gradient(1000px 700px at 100% 0%, #ffd9b5 10%, transparent 60%),
    var(--bg);
  color: var(--ink);
}

.app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

.app:has(.game-screen.analysis-mode:not(.hidden)) {
  max-width: none;
}

.hidden {
  display: none !important;
}

.screen.hidden {
  display: none;
}

.panel {
  background: linear-gradient(160deg, #fffaf0, #fff5e8);
  border: 2px solid #2a353a;
  border-radius: 18px;
  padding: 1.1rem 1.1rem 1.2rem;
  box-shadow: 0 8px 24px var(--shadow);
}

.landing-screen h1,
.instructions-panel h2 {
  margin: 0;
  font-size: clamp(1.6rem, 2.2vw, 2.2rem);
  letter-spacing: 0.04em;
}

.hero-copy {
  margin: 0.55rem 0 0;
  max-width: 48ch;
  line-height: 1.45;
}

.instructions-panel p {
  margin: 0.6rem 0 0;
  line-height: 1.4;
}

.instructions-panel ul {
  margin: 0.6rem 0 0;
  padding-left: 1.1rem;
  line-height: 1.4;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 0.95rem;
}

.landing-screen {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.landing-topbar {
  align-items: center;
}

.landing-actions {
  margin-top: 0;
  justify-content: flex-end;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.game-screen {
  text-align: left;
}

.game-shell {
  width: var(--board-shell-width);
  max-width: 100%;
  margin: 0 auto;
}

.title-block {
  min-width: 0;
  flex: 1 1 auto;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.title-block h2 {
  margin: 0;
  font-size: clamp(1.45rem, 2vw, 2rem);
  letter-spacing: 0.04em;
}

.title-block .splash-word {
  font-family: "Comic Sans MS", "Comic Sans", cursive;
  font-weight: 700;
  line-height: 1;
}

.title-block .splash-letter {
  display: inline-block;
}

.title-block .splash-letter:nth-child(1) { color: var(--red); }
.title-block .splash-letter:nth-child(2) { color: var(--blue); }
.title-block .splash-letter:nth-child(3) { color: var(--yellow); }
.title-block .splash-letter:nth-child(4) { color: var(--purple); }
.title-block .splash-letter:nth-child(5) { color: var(--orange); }
.title-block .splash-letter:nth-child(6) { color: var(--green); }

.subtitle {
  margin: 0.2rem 0 0;
  opacity: 0.85;
}

.score-pill {
  margin: 0;
  width: fit-content;
  padding: 0.35rem 0.72rem;
  border: 2px solid #2a353a;
  border-radius: 999px;
  background: #fff2db;
  font-weight: 700;
}

.topbar-actions {
  flex: 0 1 430px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: 430px;
}

.game-screen.analysis-mode .topbar {
  align-items: stretch;
}

.game-screen.analysis-mode {
  --board-render-width: min(760px, calc((100vh - 190px) * 1.14));
}

.game-screen.analysis-mode .game-shell {
  width: min(calc(100vw - 2rem), calc(var(--board-shell-width) * 2 + 94px));
  max-width: none;
}

.game-screen.analysis-mode .board-layout {
  display: grid;
  grid-template-columns: auto var(--board-shell-width) var(--board-shell-width);
  align-items: start;
  justify-content: space-between;
  gap: 0.35rem;
  width: 100%;
}

.game-screen.analysis-mode #analysis-graph {
  width: 100%;
  max-width: 100%;
}

.game-screen.analysis-mode .analysis-graph-wrap {
  width: var(--board-shell-width);
}

.game-screen.analysis-mode .topbar-actions {
  display: none;
}

.game-screen.analysis-mode .title-block {
  flex: 1 1 100%;
}

.game-screen.analysis-mode .subtitle {
  max-width: none;
}

.game-screen.analysis-mode .score-pill {
  display: none;
}

.move-error {
  border: 2px solid #9f2d28;
  border-radius: 12px;
  background: #fff2ee;
  padding: 0.6rem 0.75rem;
  box-shadow: 0 3px 10px var(--shadow);
  width: min(430px, 100%);
}

.move-error.hidden {
  display: none;
}

.move-error-text {
  margin: 0 0 0.45rem;
  font-size: 0.94rem;
  line-height: 1.35;
}

.move-error-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
}

.move-error button {
  border-color: #7d2622;
  padding: 0.35rem 0.9rem;
}

.game-screen.demo-mode #move-error-ok-btn {
  margin-left: auto;
}

.controls {
  display: flex;
  gap: 0.75rem;
  margin: 1rem 0 0.8rem;
  flex-wrap: wrap;
}

.controls #analysis-btn.active {
  background: #ffe2b6;
}

.analysis-mix-feedback {
  margin: 0;
  align-self: center;
  color: #8d2a22;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.25;
}

.no-moves-notice {
  margin: 0.1rem 0 0.75rem;
  color: #c32020;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}

.board-layout {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 0.65rem;
}

.analysis-palette {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding-top: 0.45rem;
}

.analysis-graph-wrap {
  background: linear-gradient(160deg, #fffaf0, #fff5e8);
  border: 2px solid #2a353a;
  border-radius: 16px;
  padding: 0.4rem;
  box-shadow: 0 8px 24px var(--shadow);
  overflow: hidden;
  display: flex;
}

#analysis-graph {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 100%;
  overflow: hidden;
}

.analysis-swatch {
  width: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0;
  border: 2px solid #1d2a31;
  box-shadow: 0 2px 5px var(--shadow);
  clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
  padding: 0;
}

.analysis-swatch-count {
  color: #ffffff;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  text-shadow:
    0 0 1px #0f1a20,
    0 1px 0 #0f1a20;
  pointer-events: none;
  user-select: none;
}

.analysis-swatch.red {
  background: var(--red);
}

.analysis-swatch.blue {
  background: var(--blue);
}

.analysis-swatch.yellow {
  background: var(--yellow);
}

.analysis-swatch.selected {
  border-color: #ffffff;
  box-shadow:
    0 0 0 2px #152128,
    0 2px 5px var(--shadow);
}

.analysis-swatch.limit-reached,
.analysis-swatch:disabled {
  filter: grayscale(1);
  opacity: 0.45;
  cursor: not-allowed;
}

.graph-edge {
  stroke: #25363f;
  stroke-width: 2.4;
  opacity: 0.95;
}

.graph-node .node-circle {
  stroke: #152128;
  stroke-width: 2;
  cursor: grab;
}

.graph-node.selected .node-circle {
  stroke: #111;
  stroke-width: 4;
  animation: selection-border-blink 0.333s steps(1, end) 1;
}

.graph-node .node-label {
  font-size: 24px;
  font-weight: 700;
  fill: #ffffff;
  stroke: #0f1a20;
  stroke-width: 0.85;
  paint-order: stroke fill;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

button {
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  padding: 0.5rem 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 5px var(--shadow);
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

button:disabled:hover {
  transform: none;
}

button:focus-visible {
  outline: 3px solid #68a0ff;
  outline-offset: 2px;
}

.board-wrap {
  background: linear-gradient(160deg, #fffaf0, #fff5e8);
  border: 2px solid #2a353a;
  border-radius: 16px;
  padding: 0.5rem;
  box-shadow: 0 8px 24px var(--shadow);
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
}

.game-shell .board-wrap {
  width: 100%;
}

.board-layout .board-wrap {
  width: fit-content;
}

#board,
#landing-board {
  display: block;
  width: var(--board-render-width);
  max-width: 100%;
  margin: 0 auto;
  user-select: none;
}

#board {
  touch-action: none;
}

.game-screen.analysis-mode.analysis-cursor-active .board-wrap,
.game-screen.analysis-mode.analysis-cursor-active #board,
.game-screen.analysis-mode.analysis-cursor-active #board .tile-group .inner {
  cursor: var(--analysis-cursor) !important;
}

.outer {
  fill: none;
  stroke: #33434d;
  stroke-width: 1.8;
  pointer-events: none;
}

.tile-group .inner {
  stroke: #1d2a31;
  stroke-width: 1.1;
}

.game-screen.analysis-mode .tile-group.selected-blob .inner {
  stroke: #111;
  stroke-width: 3;
  animation: selection-border-blink 0.333s steps(1, end) 1;
}

@keyframes selection-border-blink {
  0%,
  49.999% {
    stroke: #ffffff;
  }
  50%,
  100% {
    stroke: #111;
  }
}

.tile-group.draggable .inner {
  cursor: grab;
}

.tile-group.dragging-source .inner {
  fill: var(--white);
}

#drag-layer .drag-inner,
#demo-layer .drag-inner {
  stroke: #111;
  stroke-width: 1;
  opacity: 0.9;
}

#preview-layer .overlap-preview {
  stroke: none;
  opacity: 0.8;
}

.game-screen.demo-mode .controls,
.game-screen.demo-mode .subtitle,
.game-screen.demo-mode .analysis-palette,
.game-screen.demo-mode .analysis-graph-wrap {
  display: none;
}

.game-screen.analysis-mode #play-demo-btn {
  display: none;
}

@media (max-width: 720px) {
  :root {
    --board-render-width: min(92vw, calc((100vh - 360px) * 1.14));
  }

  .topbar {
    flex-direction: column;
  }

  .game-screen.analysis-mode {
    --board-render-width: min(95vw, calc((100vh - 250px) * 1.14));
  }

  .game-shell {
    width: 100%;
  }

  .board-layout {
    flex-direction: column;
    align-items: center;
  }

  .analysis-palette {
    flex-direction: row;
    padding-top: 0;
  }

  #analysis-graph {
    width: 100%;
    max-width: 100%;
  }

  .topbar-actions,
  .move-error {
    width: 100%;
  }

  button {
    padding: 0.45rem 0.9rem;
  }
}
