:root {
  color-scheme: light;
  --ink: #3a3a3a;
  --muted: #8a9ab0;
  --muted-light: #dde4ee;
  --muted-mid: #b4c0ce;
  --surface: #f5f5f5;
  --panel-bg: #ffffff;
  --body-bg: #eef1f6;
  --cell-bg: var(--muted-light);
  --chip-bg: #ffffff;
  --panel-soft-bg: rgba(255, 255, 255, 0.76);
  --tooltip-bg: #1e2330;
  --shadow-sm: 0 2px 6px rgba(100, 130, 170, 0.14);
  --shadow-md: 0 6px 20px rgba(100, 130, 170, 0.16);
  --shadow-lg: 0 14px 36px rgba(100, 130, 170, 0.18);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --danger: #e05252;
  --stat-width: 116px;
  --stat-gap: 10px;
  --stats-width: calc((var(--stat-width) * 3) + (var(--stat-gap) * 2));
}

body[data-theme="dark"] {
  color-scheme: dark;
  --ink: #edf3fb;
  --muted: #8fa1b8;
  --muted-light: #2d3848;
  --muted-mid: #46566e;
  --surface: #111827;
  --panel-bg: #182233;
  --body-bg: #0d1420;
  --cell-bg: #303c4e;
  --chip-bg: #111827;
  --panel-soft-bg: rgba(24, 34, 51, 0.82);
  --tooltip-bg: #070b12;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.20);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.24);
  --shadow-lg: 0 18px 42px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  overflow: hidden;
}

body {
  width: 100%;
  max-width: 100%;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: clip;
  background: var(--body-bg);
  color: var(--ink);
  font-family: "Manrope", ui-sans-serif, system-ui, -apple-system, sans-serif;
}

button {
  min-height: 42px;
  border: none;
  border-radius: 6px;
  background: var(--muted);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 160ms var(--spring),
    background 140ms var(--smooth),
    box-shadow 140ms var(--smooth);
  box-shadow: 0 3px 0 rgba(80, 110, 150, 0.20);
}

button:hover:not(:disabled):not(.cell):not(.icon-btn):not(.theme-toggle) {
  background: color-mix(in srgb, var(--muted) 85%, #000);
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(80, 110, 150, 0.12);
}

button:active:not(:disabled):not(.cell):not(.icon-btn):not(.theme-toggle) {
  transform: translateY(3px);
  box-shadow: none;
}

button:disabled:not(.cell):not(.icon-btn):not(.theme-toggle) {
  cursor: not-allowed;
}

.game-shell {
  position: relative;
  width: min(100%, 620px);
  max-width: 100%;
  min-width: 0;
  display: grid;
  gap: 12px;
  padding-top: 0;
}

.app-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 32px;
  padding: 0 8px;
}

.app-brand {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-width: 0;
}

.app-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  display: block;
}

.app-title {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.app-title span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.top-bar,
.control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border-radius: 12px;
  background: var(--panel-bg);
  box-shadow: var(--shadow-md);
}

.top-bar {
  justify-content: center;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.control-bar {
  padding: 16px 20px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
}

.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0;
  width: auto;
  min-height: 24px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  box-shadow: none;
  cursor: pointer;
}

.theme-toggle:hover:not(:disabled),
button.theme-toggle:hover:not(:disabled),
button.theme-toggle:active:not(:disabled) {
  background: transparent;
  color: var(--muted);
  transform: none;
  box-shadow: none;
}

.theme-toggle:hover:not(:disabled) .theme-toggle-track {
  box-shadow:
    inset 0 0 0 1px rgba(138, 154, 176, 0.36),
    0 2px 6px rgba(80, 110, 150, 0.14);
}

.theme-toggle::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--tooltip-bg);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
  text-transform: none;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms var(--smooth);
  z-index: 40;
}

.theme-toggle::before {
  content: "";
  position: absolute;
  top: calc(100% + 3px);
  right: 15px;
  border: 5px solid transparent;
  border-bottom-color: var(--tooltip-bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms var(--smooth);
  z-index: 40;
}

.theme-toggle:hover:not(:disabled)::after,
.theme-toggle:hover:not(:disabled)::before {
  opacity: 1;
}

.theme-toggle-track {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--muted-light);
  box-shadow:
    inset 0 0 0 1px rgba(138, 154, 176, 0.30),
    0 2px 6px rgba(80, 110, 150, 0.14);
  transition: background 160ms var(--smooth), box-shadow 160ms var(--smooth);
}

.theme-toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: transparent;
  box-shadow: none;
  font-size: 15px;
  line-height: 1;
  pointer-events: none;
  transition: transform 180ms var(--spring);
}

.theme-toggle[aria-pressed="true"] .theme-toggle-track {
  background: var(--muted);
}

.theme-toggle[aria-pressed="true"] .theme-toggle-knob {
  transform: translateX(18px);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--stat-gap);
  width: 100%;
}

.stat {
  position: relative;
  width: 100%;
  min-width: 0;
  padding: 8px 6px;
  border-radius: 8px;
  background: var(--panel-bg);
  text-align: center;
  box-shadow: var(--shadow-md);
}


.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat strong {
  display: block;
  margin-top: 2px;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.counter-counting {
  animation: counter-counting-pop 180ms var(--spring) both;
}

.counter-final {
  animation: number-final-pop 180ms var(--spring) both;
}

@keyframes counter-counting-pop {
  0%   { transform: translateY(0) scale(1); }
  45%  { transform: translateY(-1px) scale(1.08); }
  100% { transform: translateY(0) scale(1); }
}

.score-multiplier {
  position: absolute;
  left: 50%;
  top: -10px;
  display: block;
  min-width: 42px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--tooltip-bg);
  color: #fff;
  font-size: 0.68rem;
  font-style: normal;
  font-weight: 900;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px) scale(0.86);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.24);
  z-index: 3;
}

.score-multiplier.show {
  animation: score-multiplier-pop 900ms var(--spring) forwards;
}

@keyframes score-multiplier-pop {
  0%   { opacity: 0; transform: translate(-50%, 8px) scale(0.86); }
  20%  { opacity: 1; transform: translate(-50%, -5px) scale(1.1); }
  38%  { transform: translate(-50%, -2px) scale(0.98); }
  70%  { opacity: 1; transform: translate(-50%, -6px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -14px) scale(0.94); }
}

.goal-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, var(--stats-width));
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-radius: 12px;
  background: var(--panel-bg);
  box-shadow: var(--shadow-md);
}

.goal-copy {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  max-width: 100%;
}

.goal-copy strong {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 0;
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

.goal-prefix {
  color: var(--muted);
}

#goal-text-icon,
#goal-text-label {
  display: none;
}

.goal-text-icon {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

.goal-text-icon-chip {
  --goal-color: #d94a52;
  width: 15px;
  flex: 0 0 15px;
  aspect-ratio: 0.866 / 1;
  clip-path: url(#hex-r);
  background: var(--goal-color);
  box-shadow:
    0 2px 4px rgba(80, 110, 150, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.34);
}

.goal-text-icon-chip + .goal-text-icon-chip {
  margin-left: -5px;
}

.goal-meter {
  --goal-count-width: 10em;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: end;
  min-width: min(100%, 220px);
  width: 100%;
  min-height: 44px;
  overflow: visible;
}

.goal-tiles {
  --goal-color: #d94a52;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-height: 44px;
  overflow: visible;
  transform-origin: right center;
}

.goal-tile-wrap {
  flex: 0 0 24px;
  width: 24px;
  aspect-ratio: 0.866 / 1;
  clip-path: url(#hex-r);
  background: var(--panel-bg);
  display: grid;
  place-items: center;
  position: relative;
}

.goal-tile-wrap.goal-tile-badge {
  flex-basis: 44px;
  width: 44px;
  clip-path: none;
  background: transparent;
  overflow: visible;
}

.goal-tile-wrap.new {
  z-index: 12;
  animation: goal-chip-stack 1080ms var(--spring) both;
}

.goal-tile-wrap.goal-tile-badge.new {
  animation: none;
  z-index: auto;
}

.goal-tile-wrap.goal-tile-badge.new .goal-tile-chip {
  animation: goal-badge-pop 280ms var(--spring) both;
}

@keyframes goal-badge-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.18); }
  60%  { transform: scale(0.92); }
  80%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.goal-tile-wrap + .goal-tile-wrap {
  margin-left: -11px;
}


.goal-tile-chip {
  width: calc(100% - 4px);
  aspect-ratio: 0.866 / 1;
  clip-path: url(#hex-r);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.35), transparent 38%),
    var(--goal-color);
  position: relative;
  display: grid;
  place-items: center;
}

.goal-tile-badge .goal-tile-chip {
  width: 30px;
  box-shadow:
    0 10px 18px rgba(72, 96, 132, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.goal-tile-stack-count {
  position: absolute;
  right: -5px;
  bottom: 5px;
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 22px;
  padding: 0 4px;
  border-radius: 999px;
  background: #fff;
  color: #111827;
  font-size: 0.62rem;
  font-weight: 900;
  line-height: 1;
  box-shadow:
    0 3px 0 rgba(80, 110, 150, 0.22),
    0 7px 14px rgba(72, 96, 132, 0.18);
  z-index: 2;
}

.goal-tile-stack-number {
  display: inline-block;
  transform-origin: center;
}

.goal-tile-stack-number.goal-count-roll {
  animation: slot-spin 160ms linear infinite;
}

.goal-tile-stack-number.goal-count-final {
  animation: number-final-pop 200ms var(--spring) both;
}

.goal-count {
  position: relative;
  z-index: 5;
  width: var(--goal-count-width);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.board-wrap {
  position: relative;
  padding: clamp(12px, 3vw, 20px);
  border-radius: 14px;
  background: var(--panel-bg);
  box-shadow: var(--shadow-lg);
  transition: box-shadow 200ms var(--smooth), outline 200ms var(--smooth);
}

.board-wrap.erase-active {
  box-shadow: var(--shadow-lg), 0 0 0 3px rgba(255, 45, 85, 0.55);
  outline: none;
}

.board-wrap.erase-active::after {
  content: "削除モード";
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 45, 85, 0.88);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  white-space: nowrap;
  pointer-events: none;
  animation: erase-badge-in 180ms var(--spring) both;
  z-index: 10;
}

@keyframes erase-badge-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-4px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.board {
  --hex-size: clamp(34px, 11vw, 62px);
  --hex-gap: clamp(3px, 0.7vw, 6px);
  --hex-height: calc(var(--hex-size) / 0.866);
  --row-step: calc(var(--hex-height) - (var(--hex-size) * 0.29) + var(--hex-gap));
  position: relative;
  width: min(100%, 520px);
  margin: 0 auto;
  padding: calc(var(--hex-size) * 0.12) calc(var(--hex-size) * 0.34) calc(var(--hex-size) * 0.18);
  height: calc(var(--row-step) * 5 + var(--hex-height) + (var(--hex-size) * 0.12) + (var(--hex-size) * 0.18));
}

.board-row {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--row-step) * var(--i, 0));
  display: flex;
  justify-content: center;
  gap: var(--hex-gap);
  transform: translateX(calc((var(--hex-size) + var(--hex-gap)) / -4));
}

.board-row.offset {
  transform: translateX(calc((var(--hex-size) + var(--hex-gap)) / 4));
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--hex-size);
  min-height: auto;
  min-width: 0;
  aspect-ratio: 0.866 / 1;
  border: 0;
  clip-path: url(#hex-r);
  background: var(--cell-bg);
  cursor: pointer;
  transition:
    transform 200ms var(--spring),
    filter 140ms var(--smooth),
    background 140ms var(--smooth);
  box-shadow: none;
}

.cell:hover:not(.filled):not(.locked):not(.inactive) {
  background: var(--muted-mid);
}

.cell.inactive:hover {
  filter: brightness(0.88);
}

.cell.erase-target {
  filter: drop-shadow(0 0 8px rgba(224, 82, 82, 0.75));
  cursor: crosshair;
}

.cell.erase-target:hover {
  filter: drop-shadow(0 0 12px rgba(224, 82, 82, 0.9));
  transform: scale(1.05);
}

.cell.locked,
.cell.inactive {
  cursor: default;
}

.cell.inactive {
  background:
    repeating-linear-gradient(
      45deg,
      var(--muted) 0px,
      var(--muted) 4px,
      var(--muted-light) 4px,
      var(--muted-light) 10px
    );
  opacity: 0.6;
}

.tile {
  --tile-color: #d94a52;
  position: relative;
  display: grid;
  place-items: center;
  width: 82%;
  aspect-ratio: 0.866 / 1;
  border: 0;
  clip-path: url(#hex-r);
  background:
    radial-gradient(ellipse 58% 42% at 28% 22%, rgba(255,255,255,0.16) 0%, transparent 100%),
    linear-gradient(
      150deg,
      color-mix(in srgb, var(--tile-color) 78%, #fff) 0%,
      var(--tile-color) 55%,
      color-mix(in srgb, var(--tile-color) 84%, #000) 100%
    );
  color: #ffffff;
  font-weight: 900;
  text-shadow: 0 1px 3px rgba(80, 110, 150, 0.26);
  filter: drop-shadow(0 3px 6px rgba(80, 110, 150, 0.22));
  transition: transform 180ms var(--spring), filter 140ms var(--smooth);
}

.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: inherit;
  background:
    radial-gradient(ellipse 62% 46% at 28% 20%, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0.02) 52%, transparent 72%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.03) 0%, transparent 48%, rgba(0, 0, 0, 0.05) 100%);
  pointer-events: none;
  z-index: 1;
}

.cell .tile {
  width: 100%;
}

.tile.multi-layer {
  --bottom-color: #555;
  background:
    linear-gradient(
      150deg,
      color-mix(in srgb, var(--tile-color) 78%, #fff) 0%,
      var(--tile-color) 55%,
      color-mix(in srgb, var(--tile-color) 92%, #000) 75%,
      color-mix(in srgb, var(--tile-color) 40%, var(--bottom-color)) 75%,
      var(--bottom-color) 76%
    );
}


.tile-count {
  position: relative;
  z-index: 20;
  font-size: clamp(1rem, 4vw, 1.7rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.cell.number-roll .tile-count {
  animation: slot-spin 55ms steps(1, end) infinite;
}

.cell.number-final .tile-count {
  animation: number-final-pop 200ms var(--spring) both;
}

.cell.number-final .tile {
  animation: tile-glow 200ms var(--smooth) both;
}

.next-tiles {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
}

.preview-tile {
  width: 52px;
  cursor: pointer;
  transition:
    transform 180ms var(--spring),
    filter 140ms var(--smooth);
}

.preview-tile:hover {
  transform: translateY(-3px) scale(1.1);
  filter: drop-shadow(0 6px 10px rgba(80, 110, 150, 0.26));
}

.preview-tile.selected {
  transform: scale(1.12) translateY(-3px);
  filter:
    drop-shadow(0 0 0 3px rgba(255,255,255,0.9))
    drop-shadow(0 6px 12px rgba(80, 110, 150, 0.26));
}

.next-tile-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 160px;
}

.actions {
  display: flex;
  gap: 12px;
}

.icon-btn {
  position: relative;
  width: 64px;
  height: 64px;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  transition: transform 160ms var(--spring);
}

.icon-btn:hover:not(:disabled) {
  background: transparent;
  box-shadow: none;
  transform: translateY(2px);
}

.icon-btn:active:not(:disabled) {
  transform: translateY(3px);
}

.icon-btn-bg {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--muted);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--muted) 60%, #000);
  transition: background 140ms var(--smooth), box-shadow 140ms var(--smooth), border-radius 140ms var(--smooth);
}

.icon-btn:hover:not(:disabled) .icon-btn-bg {
  background: color-mix(in srgb, var(--muted) 82%, #000);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--muted) 50%, #000);
  border-radius: 18px;
}

.icon-btn:active:not(:disabled) .icon-btn-bg {
  box-shadow: none;
  border-radius: 14px;
}

.icon-btn:disabled .icon-btn-bg {
  opacity: 1;
}

.icon-btn.no-charge .icon-btn-bg {
  opacity: 0.4;
}

.icon-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--tooltip-bg);
  color: #fff;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
  padding: 5px 10px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms var(--smooth), transform 140ms var(--smooth);
  z-index: 30;
}

.icon-btn::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  border: 5px solid transparent;
  border-top-color: var(--tooltip-bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms var(--smooth), transform 140ms var(--smooth);
  z-index: 30;
}

.icon-btn:hover:not(:disabled)::after,
.icon-btn:hover:not(:disabled)::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.icon-btn-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 99px;
  background: var(--chip-bg);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 24px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  pointer-events: none;
}

body[data-theme="dark"] .icon-btn-badge {
  background: #c2cfdd;
  color: #172234;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.34),
    inset 0 0 0 1px rgba(237, 243, 251, 0.55);
}

#erase-button.active .icon-btn-bg {
  background: #c0514f;
}


.color-total-bar {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
  padding: 10px 16px 12px;
  border-radius: 10px;
  background: var(--panel-soft-bg);
  box-shadow: var(--shadow-sm);
}

.color-total-bar .eyebrow {
  margin: 0;
  flex: 0 0 auto;
  font-size: 0.68rem;
}

.color-totals {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
}

.inspiration-credit {
  width: 100%;
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 500;
  line-height: 1.4;
  opacity: 0.68;
  text-align: center;
}

.inspiration-credit a {
  color: inherit;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color 160ms var(--smooth);
}

.inspiration-credit a:hover {
  color: var(--ink);
}

.color-total-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px rgba(138, 154, 176, 0.18);
}

.color-total-icon {
  --color-total: #d94a52;
  width: 13px;
  flex: 0 0 13px;
  aspect-ratio: 0.866 / 1;
  clip-path: url(#hex-r);
  background: var(--color-total);
}

.color-total-name {
  color: var(--muted);
}

.color-total-count {
  min-width: 1.5em;
  color: var(--ink);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.game-over {
  position: absolute;
  inset: 12px;
  display: grid;
  place-content: center;
  gap: 10px;
  border-radius: 10px;
  background: rgba(10, 8, 6, 0.80);
  color: #ffffff;
  text-align: center;
}

.game-over[hidden] {
  display: none;
}

.game-over strong {
  font-size: clamp(2rem, 8vw, 4rem);
}

.game-over span {
  color: #d0d0d0;
  font-weight: 600;
}

.game-over-restart {
  margin-top: 8px;
  padding: 12px 28px;
  border: none;
  border-radius: 12px;
  background: #ffffff;
  color: #1e2330;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms var(--spring), background 120ms var(--smooth), color 120ms var(--smooth);
}

.game-over-restart:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
}

.game-over-restart:active {
  transform: translateY(3px);
  box-shadow: none;
}

.cell.merge-flash .tile {
  animation: merge-pop 420ms var(--spring) both;
}

.cell.clear-flash {
  animation: clear-burst 320ms var(--smooth) both;
}

.cell.chain-flash .tile {
  animation: chain-pop 150ms var(--spring) both;
}

@keyframes tile-clear-out {
  0%   { transform: scale(1);    opacity: 1;   filter: brightness(1); }
  25%  { transform: scale(1.18); opacity: 0.9; filter: brightness(1.6); }
  100% { transform: scale(1.5);  opacity: 0;   filter: brightness(2); }
}

.cell.tile-clear-out .tile {
  animation: tile-clear-out 520ms var(--smooth) forwards;
}

@keyframes tile-absorb {
  0%   { transform: scale(1);   opacity: 1; }
  100% { transform: scale(0.2); opacity: 0; }
}

.cell.tile-absorb .tile {
  animation: tile-absorb 110ms var(--smooth) forwards;
}

@keyframes merge-pop {
  0%   { transform: scale(0.82); }
  18%  { transform: scaleX(1.28) scaleY(0.78); filter: brightness(1.3); }
  34%  { transform: scaleX(0.86) scaleY(1.22); filter: brightness(1.1); }
  48%  { transform: scaleX(1.12) scaleY(0.93); }
  60%  { transform: scaleX(0.95) scaleY(1.07); }
  72%  { transform: scaleX(1.05) scaleY(0.97); }
  84%  { transform: scaleX(0.99) scaleY(1.02); }
  100% { transform: scale(1);   filter: brightness(1); }
}

@keyframes chain-pop {
  0%   { transform: scale(0.88); filter: brightness(1.3); }
  55%  { transform: scale(1.14); }
  100% { transform: scale(1); }
}

@keyframes clear-burst {
  0%   { filter: drop-shadow(0 0 0px rgba(255,220,50,0)) brightness(1); }
  32%  { filter: drop-shadow(0 0 18px rgba(255,220,50,1)) brightness(1.7); }
  65%  { filter: drop-shadow(0 0 10px rgba(255,190,50,0.5)) brightness(1.2); }
  100% { filter: drop-shadow(0 0 0px rgba(255,220,50,0)) brightness(1); }
}

@keyframes slot-spin {
  0%   { transform: translateY(-3px) scaleY(0.86); opacity: 0.65; }
  35%  { transform: translateY(0)    scaleY(1.05); opacity: 1;    }
  70%  { transform: translateY(3px)  scaleY(0.86); opacity: 0.65; }
  100% { transform: translateY(-3px) scaleY(0.86); opacity: 0.65; }
}

@keyframes number-final-pop {
  0%   { transform: scale(1.65) translateY(-1px); opacity: 0.75; }
  55%  { transform: scale(0.9); opacity: 1; }
  80%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes tile-exit {
  0%   { transform: scale(1) translateY(0); opacity: 1; filter: blur(0px); }
  40%  { transform: scale(1.08) translateY(-4px); opacity: 0.8; }
  100% { transform: scale(0.5) translateY(-14px); opacity: 0; filter: blur(2px); }
}

.preview-tile.tile-exit {
  animation: tile-exit 220ms var(--spring) forwards;
  pointer-events: none;
}

@keyframes tile-pop {
  0%   { transform: translateY(-3px) scale(1.12); }
  35%  { transform: scaleX(1.2) scaleY(0.82); }
  100% { transform: scale(1.12) translateY(-3px); }
}

.preview-tile.tile-pop {
  animation: tile-pop 160ms var(--spring) both;
}

@keyframes tile-place {
  0%   { transform: scale(0.4) translateY(6px); opacity: 0.6; }
  55%  { transform: scale(1.22) translateY(-3px); opacity: 1; }
  75%  { transform: scale(0.93) translateY(1px); }
  90%  { transform: scale(1.06); }
  100% { transform: scale(1) translateY(0); }
}

.tile.placing {
  animation: tile-place 260ms var(--spring) both;
}

@keyframes tile-glow {
  0%   { filter: drop-shadow(0 0 18px rgba(255,255,255,0.95)) brightness(1.5); }
  100% { filter: drop-shadow(0 3px 6px rgba(80, 110, 150, 0.22)) brightness(1); }
}

.level-clear-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20, 30, 50, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  animation: overlay-in 160ms var(--smooth) both;
}

.level-clear-overlay[hidden] {
  display: none;
}

.level-clear-popup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(90vw, 420px);
  padding: 40px 48px;
  border-radius: 20px;
  background: var(--panel-bg);
  box-shadow: 0 24px 60px rgba(80, 110, 150, 0.28);
  text-align: center;
  animation: popup-in 260ms var(--spring) both;
}

.level-clear-eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.level-clear-level {
  margin: 0;
  font-size: 3rem;
  font-weight: 800;
  color: var(--ink);
  line-height: 1;
}

.level-clear-message {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
}

.level-clear-btn {
  margin-top: 12px;
  padding: 0 28px;
  min-height: 44px;
  font-size: 1rem;
}

.cheat-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(20, 30, 50, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 120;
  animation: overlay-in 160ms var(--smooth) both;
}

.cheat-overlay[hidden] {
  display: none;
}

.cheat-popup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(100%, 340px);
  padding: 48px 44px;
  border-radius: 18px;
  background: var(--panel-bg);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(80, 110, 150, 0.3);
  text-align: center;
  animation: popup-in 260ms var(--spring) both;
}

.cheat-popup strong {
  font-size: 1.35rem;
  line-height: 1.15;
}

.cheat-popup span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.5;
}

.cheat-btn {
  margin-top: 6px;
  min-height: 42px;
  padding: 0 28px;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes popup-in {
  from { transform: scale(0.8) translateY(12px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes goal-chip-stack {
  0% {
    opacity: 0;
    transform: translateX(128px) translateY(-18px) scale(0.34) rotate(28deg);
  }
  30% {
    opacity: 1;
    transform: translateX(52px) translateY(-6px) scale(0.84) rotate(12deg);
  }
  58% {
    opacity: 1;
    transform: translateX(-14px) translateY(2px) scale(1.18) rotate(-6deg);
  }
  76% {
    opacity: 1;
    transform: translateX(6px) translateY(0) scale(0.96) rotate(2deg);
  }
  100% {
    opacity: 1;
    transform: translateX(0) translateY(0) scale(1) rotate(0);
  }
}

@media (max-width: 520px) {
  body {
    padding: 8px;
    align-items: start;
  }

  .game-shell {
    gap: 8px;
    padding-top: 0;
  }

  .app-head {
    padding: 0 6px;
  }

  .top-bar,
  .goal-panel,
  .control-bar {
    display: flex;
    align-items: stretch;
    flex-direction: column;
    padding: 12px 14px;
    border-radius: 10px;
  }

  .top-bar {
    padding: 0;
  }

  .stats {
    width: 100%;
  }

  .actions {
    width: 100%;
    justify-content: center;
  }

  .color-total-bar {
    align-items: center;
    flex-direction: column;
  }

  .color-totals {
    justify-content: center;
  }

  .stat {
    flex: 1;
    width: auto;
    min-width: 0;
    padding: 6px 8px;
  }

  .stat strong {
    font-size: 1.1rem;
  }

  .actions .icon-btn {
    flex: none;
  }

  .next-tile-panel {
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 8px;
  }

  .next-tiles {
    justify-content: center;
    width: 100%;
  }

  .goal-copy {
    align-self: center;
    justify-content: center;
  }

  .goal-copy strong {
    justify-content: center;
  }

  .goal-meter {
    --goal-count-width: 9.8em;
    display: flex;
    justify-content: center;
    align-self: center;
    flex: 0 0 auto;
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }

  .goal-tiles {
    flex: 0 1 auto;
    gap: 4px;
    min-width: 0;
    min-height: 38px;
    overflow: visible;
    justify-content: flex-end;
  }

  .goal-tile-wrap {
    flex-basis: 21px;
    width: 21px;
  }

  .goal-tile-wrap.goal-tile-badge {
    flex-basis: 44px;
    width: 44px;
  }

  .goal-tile-badge .goal-tile-chip {
    width: 30px;
  }

  .goal-tile-stack-count {
    right: -4px;
    bottom: 4px;
    min-width: 20px;
    height: 20px;
    font-size: 0.58rem;
  }

  .goal-count {
    flex: 0 0 var(--goal-count-width);
    width: var(--goal-count-width);
    font-size: 0.64rem;
    letter-spacing: -0.02em;
    line-height: 1;
    text-align: right;
    white-space: nowrap;
  }

  .board-wrap {
    padding: 8px 4px;
    border-radius: 10px;
  }

  .board {
    --hex-size: clamp(36px, 11.8vw, 48px);
    --hex-gap: 3px;
    width: 100%;
    padding: calc(var(--hex-size) * 0.1) calc(var(--hex-size) * 0.22) calc(var(--hex-size) * 0.12);
    height: calc(var(--row-step) * 5 + var(--hex-height) + (var(--hex-size) * 0.1) + (var(--hex-size) * 0.12));
  }

  .level-clear-popup {
    width: calc(100% - 32px);
    max-width: 320px;
    padding: 30px 20px;
  }

  .tutorial-popup {
    padding: 24px 20px;
  }

  .tutorial-body {
    font-size: 0.82rem;
    line-height: 1.65;
  }
}

.rock-cell {
  cursor: not-allowed !important;
}

.rock-cell:hover .rock-tile,
.rock-cell:focus .rock-tile {
  filter: brightness(0.85);
}

.rock-tile {
  width: 100%;
  height: 100%;
  clip-path: url(#hex-r);
  background: transparent;
  display: grid;
  place-items: center;
}

.rock-tile::after {
  content: "🪨";
  font-size: 1.8em;
  line-height: 1;
}

.chain-badge {
  position: absolute;
  transform: translateX(-50%) translateY(calc(-100% - 8px));
  background: var(--tooltip-bg);
  color: #fff;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  animation: chain-tooltip 1.0s ease forwards;
}

.chain-badge::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--tooltip-bg);
}

@keyframes chain-tooltip {
  0%   { opacity: 0; transform: translateX(-50%) translateY(calc(-100% - 8px + 12px)) scale(0.8); }
  18%  { opacity: 1; transform: translateX(-50%) translateY(calc(-100% - 8px - 4px)) scale(1.08); }
  32%  { transform: translateX(-50%) translateY(calc(-100% - 8px + 2px)) scale(0.97); }
  46%  { transform: translateX(-50%) translateY(calc(-100% - 8px - 2px)) scale(1.02); }
  60%  { transform: translateX(-50%) translateY(calc(-100% - 8px)) scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(calc(-100% - 8px - 8px)) scale(0.95); }
}

.tutorial-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 30, 50, 0.50);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  animation: overlay-in 160ms var(--smooth) both;
}

.tutorial-overlay[hidden] {
  display: none;
}

.tutorial-popup {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 480px);
  max-height: 90dvh;
  padding: 32px 36px;
  border-radius: 20px;
  background: var(--panel-bg);
  box-shadow: 0 24px 60px rgba(80, 110, 150, 0.28);
  animation: popup-in 260ms var(--spring) both;
}

.tutorial-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--ink);
}

.tutorial-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--ink);
  font-size: 0.88rem;
  line-height: 1.7;
  overflow-y: auto;
  min-height: 0;
}

.tutorial-body p {
  margin: 0;
}

.tutorial-body ul {
  margin: 0;
  padding-left: 1.4em;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tutorial-body strong {
  color: var(--ink);
}

.tutorial-note {
  margin: 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
}

.tutorial-btn {
  align-self: stretch;
  padding: 14px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 800;
  background: var(--muted);
  color: #fff;
  box-shadow: none;
}
