:root {
  color-scheme: dark;
  --bg: #15171a;
  --panel: rgba(28, 29, 33, 0.94);
  --panel-2: rgba(41, 39, 43, 0.94);
  --ink: #f8f0e2;
  --muted: #c4b6a4;
  --line: rgba(244, 224, 184, 0.22);
  --line-strong: rgba(244, 224, 184, 0.42);
  --burgundy: #8d3549;
  --burgundy-deep: #4a202c;
  --teal: #2f9a89;
  --gold: #d5a94e;
  --gold-light: #f2d385;
  --red: #d65342;
  --stone: #20262b;
  --tile: #ece3d2;
  --tile-ink: #292521;
  --route: #c69038;
  --route-light: #ffe0a3;
  --shadow: 0 26px 70px rgba(0, 0, 0, 0.34);
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 8%, rgba(141, 53, 73, 0.36), transparent 28%),
    radial-gradient(circle at 84% 12%, rgba(47, 154, 137, 0.24), transparent 30%),
    linear-gradient(135deg, rgba(213, 169, 78, 0.08) 0 11%, transparent 11% 89%, rgba(141, 53, 73, 0.1) 89% 100%),
    linear-gradient(180deg, #1c1d22, #111316);
  letter-spacing: 0;
  touch-action: manipulation;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1300px, 100%);
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(18px, env(safe-area-inset-bottom));
}

.game-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 76px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.09), transparent 44%),
    rgba(35, 32, 37, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  padding: 11px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1px solid rgba(245, 227, 186, 0.38);
  border-radius: 8px;
  color: #fff7d8;
  background:
    radial-gradient(circle at 35% 24%, rgba(255, 255, 255, 0.24), transparent 25%),
    linear-gradient(145deg, var(--burgundy-deep), var(--burgundy));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 10px 20px rgba(0, 0, 0, 0.28);
  font-size: 28px;
  font-weight: 900;
}

.eyebrow,
.stage-number,
.meter-row span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 3px;
}

h1,
h2 {
  margin: 0;
  line-height: 1.12;
}

h1 {
  color: #fff5e1;
  font-size: clamp(1.45rem, 4.2vw, 2.55rem);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.28);
}

.header-actions {
  display: flex;
  justify-content: flex-end;
}

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

.play-panel,
.side-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
    var(--panel);
  box-shadow: var(--shadow);
  padding: 12px;
}

.play-panel {
  display: grid;
  gap: 10px;
}

.side-panel {
  display: grid;
  gap: 14px;
}

.side-panel h2 {
  margin-bottom: 8px;
  color: #fff5df;
  font-size: 0.98rem;
}

.stage-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.stage-bar h2 {
  margin-top: 3px;
  color: #fff9eb;
  font-size: clamp(1.25rem, 3vw, 2rem);
}

.meter-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(66px, 1fr));
  gap: 8px;
  min-width: min(100%, 306px);
}

.meter-row div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(245, 239, 226, 0.12), rgba(245, 239, 226, 0.04));
  padding: 8px;
  text-align: center;
}

.meter-row strong {
  display: block;
  margin-top: 2px;
  color: var(--gold-light);
  font-size: 1.2rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.message {
  min-height: 42px;
  margin: 0;
  border: 1px solid rgba(213, 169, 78, 0.36);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(213, 169, 78, 0.18), rgba(213, 169, 78, 0.05)),
    rgba(255, 246, 223, 0.1);
  color: #f7ead4;
  padding: 10px 12px;
  line-height: 1.45;
}

.message.is-success {
  border-color: rgba(47, 154, 137, 0.52);
  background:
    linear-gradient(90deg, rgba(47, 154, 137, 0.24), rgba(47, 154, 137, 0.08)),
    rgba(223, 255, 245, 0.1);
  color: #d7fff4;
}

.message.is-failed {
  border-color: rgba(214, 83, 66, 0.5);
  background:
    linear-gradient(90deg, rgba(214, 83, 66, 0.22), rgba(214, 83, 66, 0.08)),
    rgba(255, 231, 225, 0.1);
  color: #ffdcd4;
}

.scene-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(245, 227, 186, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 24%),
    #101216;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.36), 0 18px 48px rgba(0, 0, 0, 0.26);
  padding: 8px;
}

.board-wrap {
  position: relative;
  width: min(640px, 100%, calc(100vh - 360px));
  max-width: 100%;
  margin: 0 auto;
}

.route-board {
  --gap: clamp(5px, 0.8vw, 9px);
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  gap: var(--gap);
  aspect-ratio: var(--cols) / var(--rows);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(135deg, #182129, #111519);
  background-size: 36px 36px, 36px 36px, auto;
  padding: var(--gap);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(44, 40, 34, 0.5);
  border-radius: 8px;
  color: var(--tile-ink);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.08)),
    linear-gradient(180deg, #f4ebd9, #cfc2ad);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.2),
    0 9px 18px rgba(0, 0, 0, 0.24);
}

button.tile {
  cursor: pointer;
}

button.tile:hover,
button.tile:focus-visible {
  outline: none;
  border-color: rgba(242, 211, 133, 0.9);
  filter: brightness(1.08);
}

.tile-empty {
  border-color: rgba(255, 255, 255, 0.045);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.035), transparent),
    rgba(18, 22, 26, 0.86);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16);
}

.tile-empty::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px);
  background-size: 18px 18px;
}

.tile.is-decoy {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.04)),
    linear-gradient(180deg, #dad0c1, #a99d8d);
}

.tile-s,
.tile-e {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.08)),
    linear-gradient(180deg, #dffcf2, #73c9b8);
}

.route-core,
.route-arm {
  position: absolute;
  z-index: 1;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.46), rgba(255, 255, 255, 0)),
    linear-gradient(90deg, #8b5b15, var(--route-light) 22% 78%, #8d5e16);
  box-shadow: inset 0 0 0 1px rgba(72, 44, 9, 0.42), 0 2px 5px rgba(0, 0, 0, 0.24);
}

.route-core {
  left: 50%;
  top: 50%;
  width: 40%;
  height: 40%;
  border-radius: 999px;
  transform: translate(-50%, -50%);
}

.route-arm {
  border-radius: 999px;
}

.route-n,
.route-s {
  left: 42%;
  width: 16%;
  height: 50%;
}

.route-e,
.route-w {
  top: 42%;
  width: 50%;
  height: 16%;
}

.route-n {
  top: -2px;
}

.route-s {
  bottom: -2px;
}

.route-e {
  right: -2px;
}

.route-w {
  left: -2px;
}

.token-wrap {
  position: absolute;
  inset: 7%;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-content: center;
  justify-content: center;
  pointer-events: none;
}

.token {
  display: grid;
  place-items: center;
  width: clamp(26px, 4.2vw, 42px);
  height: clamp(26px, 4.2vw, 42px);
  border: 2px solid rgba(255, 255, 255, 0.58);
  border-radius: 999px;
  color: #fff8e8;
  background: #5a5360;
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.28);
  font-size: clamp(0.72rem, 1.7vw, 1.05rem);
  font-weight: 900;
  line-height: 1;
}

.token-lord,
.runner {
  background: linear-gradient(145deg, #6f2335, #a13f58);
}

.token-exit {
  background: linear-gradient(145deg, #17665e, #2f9a89);
}

.token-key,
.token-treasure {
  background: linear-gradient(145deg, #9a6f1e, #d5a94e);
}

.token-butler {
  background: linear-gradient(145deg, #101820, #31404c);
}

.token-guard,
.token-fire {
  background: linear-gradient(145deg, #6f2335, #d65342);
}

.token-water {
  background: linear-gradient(145deg, #1a5d8d, #38a4d8);
}

.token-sword {
  background: linear-gradient(145deg, #496a82, #79a8c7);
}

.token-beast {
  background: linear-gradient(145deg, #345d34, #57945b);
}

.runner {
  position: absolute;
  z-index: 8;
  display: grid;
  place-items: center;
  width: clamp(30px, 5.6vw, 48px);
  height: clamp(30px, 5.6vw, 48px);
  border: 2px solid rgba(255, 255, 255, 0.64);
  border-radius: 999px;
  color: #fff8e8;
  font-size: clamp(0.8rem, 2vw, 1.1rem);
  font-weight: 900;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: left 0.14s ease, top 0.14s ease;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.32);
}

.level-list {
  display: grid;
  gap: 7px;
}

.level-button,
.primary-button,
.secondary-button,
.icon-text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.04)),
    rgba(245, 239, 226, 0.08);
  cursor: pointer;
}

.level-button {
  justify-content: flex-start;
  width: 100%;
  min-height: 54px;
  padding: 8px 10px;
  text-align: left;
}

.level-button span:first-child {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  color: #fff5de;
  background: rgba(245, 227, 186, 0.16);
  font-size: 0.78rem;
  font-weight: 900;
}

.level-button strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: #fff7e8;
  font-size: 0.88rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-button em {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.74rem;
  font-style: normal;
}

.level-button.is-active {
  border-color: rgba(213, 169, 78, 0.5);
  background:
    linear-gradient(90deg, rgba(213, 169, 78, 0.2), rgba(213, 169, 78, 0.05)),
    rgba(245, 239, 226, 0.1);
}

.level-button.is-cleared span:first-child {
  color: #08241f;
  background: var(--teal);
}

.log-box {
  display: grid;
  gap: 7px;
  min-height: 132px;
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.16);
  padding: 8px;
}

.log-entry {
  border-left: 3px solid rgba(213, 169, 78, 0.76);
  padding-left: 8px;
  color: #efe4d1;
  font-size: 0.84rem;
  line-height: 1.45;
}

.control-row {
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr) auto;
  gap: 10px;
}

.primary-button {
  border-color: rgba(141, 53, 73, 0.58);
  color: #fff5e4;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 38%),
    linear-gradient(145deg, var(--burgundy-deep), var(--burgundy));
  padding: 0 16px;
}

.secondary-button,
.icon-text-button {
  padding: 0 12px;
}

.primary-button:disabled,
.secondary-button:disabled,
.icon-text-button:disabled,
.level-button:disabled {
  opacity: 0.44;
  cursor: not-allowed;
}

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

  .side-panel {
    grid-template-columns: 1fr 1fr;
  }

  .board-wrap {
    width: min(680px, 100%);
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding-left: 8px;
    padding-right: 8px;
  }

  .game-header {
    grid-template-columns: 42px minmax(0, 1fr);
    min-height: 0;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    font-size: 22px;
  }

  .header-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .header-actions button {
    width: 100%;
  }

  .stage-bar,
  .control-row {
    display: grid;
  }

  .meter-row {
    width: 100%;
    min-width: 0;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .scene-frame {
    padding: 5px;
  }

  .route-board {
    --gap: 4px;
  }

  .tile {
    border-radius: 7px;
  }

  .token-wrap {
    inset: 5%;
    gap: 2px;
  }

  .token {
    width: 27px;
    height: 27px;
    font-size: 0.72rem;
  }
}
