:root {
  --paper: #f2efe6;
  --ink: #151b1b;
  --muted: #7d807a;
  --line: #d6d1c5;
  --yellow: #ffd84d;
  --blue: #1659d9;
  --panel: #ebe7dc;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--paper); color: var(--ink); }

body {
  font-family: "Noto Sans JP", sans-serif;
  background-image: radial-gradient(rgba(21,27,27,.045) .7px, transparent .7px);
  background-size: 5px 5px;
}

button, select { font: inherit; }
button { color: inherit; }

.app { width: min(1400px, calc(100% - 72px)); margin: auto; padding-bottom: 64px; }

.topbar {
  height: 88px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); font: 900 21px/1 "DM Mono"; letter-spacing: .12em; }
.brand-mark { width: 30px; height: 30px; display: block; object-fit: contain; }
.header-actions { display: flex; gap: 10px; }
.icon-button, .about-button { height: 40px; background: transparent; border: 1px solid var(--line); cursor: pointer; }
.icon-button { width: 40px; padding: 9px; }
.icon-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sound-off { display: none; }
.muted .sound-on { display: none; }
.muted .sound-off { display: block; }
.about-button { padding: 0 15px; font-size: 12px; font-weight: 700; letter-spacing: .06em; }
.about-button span { border: 1px solid currentColor; border-radius: 50%; width: 17px; height: 17px; display: inline-grid; place-items: center; margin-left: 8px; }

.hero { display: flex; align-items: flex-end; justify-content: space-between; padding: 16px 0 42px; border-bottom: 1px solid var(--line); }
.eyebrow { font: 500 10px/1.4 "DM Mono"; letter-spacing: .18em; color: var(--muted); margin: 0 0 14px; }
h1 { font-size: clamp(40px, 5vw, 72px); line-height: 1.03; margin: 0; letter-spacing: -.07em; font-weight: 900; }
h1 em { color: var(--blue); font-style: normal; }
.intro { color: #5c605c; line-height: 2; font-size: 13px; margin: 0 5% 4px 24px; }

.ad-unit {
  width: 100%;
  min-height: 90px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.game-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 650px; }
.panel { border-right: 1px solid var(--line); padding: 35px 34px 0 0; display: flex; flex-direction: column; }
.label { font: 500 9px "DM Mono"; letter-spacing: .17em; color: var(--muted); display: block; margin-bottom: 12px; }
.difficulty { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); }
.difficulty button { border: 0; border-right: 1px solid var(--line); background: transparent; padding: 11px 2px; cursor: pointer; font-size: 10px; }
.difficulty button:last-child { border: 0; }
.difficulty button.active { color: var(--paper); background: var(--ink); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 25px; margin: 35px 0; }
.stat strong { font: 500 29px/1 "DM Mono"; letter-spacing: -.05em; }
.panel-actions { display: grid; gap: 10px; }
.primary-button { border: 0; background: var(--ink); color: white; min-height: 48px; padding: 0 18px; font-size: 12px; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; transition: transform .15s, background .15s; }
.primary-button:hover { background: var(--blue); }
.primary-button:active { transform: scale(.98); }
.primary-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.text-button { border: 1px solid var(--line); background: transparent; min-height: 42px; cursor: pointer; font-size: 11px; }
.text-button.active { color: var(--blue); border-color: var(--blue); }
.hint-dot { display: inline-block; width: 6px; height: 6px; background: var(--yellow); border-radius: 50%; margin-right: 5px; }
.keys-help { margin-top: auto; border-top: 1px solid var(--line); padding: 26px 0; display: flex; align-items: center; gap: 15px; }
.key-grid { display: grid; grid-template-columns: repeat(3, 23px); gap: 3px; }
.key-grid kbd { width: 23px; height: 23px; background: rgba(255,255,255,.65); border: 1px solid var(--line); display: grid; place-items: center; font: 10px "DM Mono"; box-shadow: 0 1px 0 #bbb; }
.keys-help p { color: var(--muted); font-size: 9px; line-height: 1.7; margin: 0; }

.maze-area { padding: 30px 0 0 42px; min-width: 0; }
.maze-meta { display: flex; justify-content: space-between; margin-bottom: 12px; font: 500 9px "DM Mono"; color: var(--muted); letter-spacing: .13em; }
.canvas-frame { position: relative; width: 100%; background: #fbfaf6; border: 1px solid var(--line); box-shadow: 0 15px 40px rgba(31,32,25,.07); touch-action: none; }
canvas { display: block; width: 100%; height: auto; }
.start-label, .goal-label { position: absolute; pointer-events: none; font: 700 8px "DM Mono"; letter-spacing: .12em; }
.start-label { color: #9c7400; transform: translate(-50%, -155%); }
.goal-label { color: var(--blue); transform: translate(-50%, 65%); }
.mobile-pad { display: none; grid-template-columns: repeat(4, 1fr); margin-top: 12px; gap: 6px; }
.mobile-pad button { height: 44px; background: transparent; border: 1px solid var(--line); }

dialog { width: min(430px, calc(100% - 36px)); border: 0; padding: 45px; background: var(--paper); box-shadow: 0 25px 100px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(16,20,20,.55); backdrop-filter: blur(4px); }
dialog h2, .clear-card h2 { font-size: 34px; line-height: 1.15; margin: 0 0 25px; letter-spacing: -.05em; }
dialog ol { margin: 0 0 30px; padding-left: 20px; color: #565b57; font-size: 13px; line-height: 2; }
.dialog-close { position: absolute; right: 14px; top: 14px; border: 0; background: transparent; font: 25px/1 sans-serif; cursor: pointer; }

.overlay { display: none; position: fixed; inset: 0; background: rgba(16,20,20,.62); backdrop-filter: blur(5px); z-index: 4; }
.clear-card { display: none; position: fixed; z-index: 5; left: 50%; top: 50%; transform: translate(-50%,-50%); width: min(390px, calc(100% - 36px)); padding: 42px; background: var(--paper); text-align: center; box-shadow: 0 25px 100px rgba(0,0,0,.3); }
.clear-card.show, .overlay.show { display: block; }
.clear-icon { display: grid; place-items: center; width: 62px; height: 62px; margin: 0 auto 25px; border-radius: 50%; background: var(--yellow); font-size: 27px; }
.clear-card p:not(.eyebrow) { font: 13px/1.8 "DM Mono"; color: var(--muted); margin: -12px 0 25px; }

@media (max-width: 850px) {
  .app { width: min(100% - 36px, 680px); }
  .hero { min-height: 210px; }
  .intro { display: none; }
  .game-shell { grid-template-columns: 1fr; }
  .panel { border-right: 0; padding: 25px 0 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
  .stats { margin: 0; }
  .panel-actions { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; }
  .keys-help { display: none; }
  .maze-area { padding: 10px 0 0; }
}

@media (max-width: 520px) {
  .app { width: calc(100% - 24px); padding-bottom: 25px; }
  .topbar { height: 68px; }
  .about-button { width: 40px; font-size: 0; padding: 0; }
  .about-button span { margin: 0; }
  .hero { min-height: 175px; padding: 35px 0 28px; }
  h1 { font-size: 42px; }
  .game-shell { min-height: 0; }
  .panel { grid-template-columns: 1fr; gap: 22px; }
  .stats { order: 2; }
  .panel-actions { grid-column: auto; order: 3; }
  .maze-area { order: 4; }
  .mobile-pad { display: grid; }
  dialog { padding: 38px 28px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
