:root {
  color-scheme: dark;
  --ink: #eff9ff;
  --muted: #9cb4c6;
  --night: #06111b;
  --panel: #0c1f2d;
  --line: #36556a;
  --cyan: #58e3d3;
  --yellow: #ffd166;
  --coral: #ff725e;
  --violet: #9c8cff;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-width: 320px; min-height: 100%; background: var(--night); }

body {
  color: var(--ink);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  overflow-x: clip;
  background:
    radial-gradient(circle at 13% 20%, rgba(88, 227, 211, .08) 0 1px, transparent 2px),
    radial-gradient(circle at 80% 70%, rgba(255, 209, 102, .1) 0 1px, transparent 2px),
    #06111b;
  background-size: 37px 37px, 53px 53px;
}

button { font: inherit; }

button:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

.app-shell {
  width: min(100%, 980px);
  height: 100svh;
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-rows: 48px minmax(0, 1fr);
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left));
}

.topbar {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid rgba(88, 227, 211, .28);
}

.brand-mark { width: 30px; height: 30px; position: relative; flex: 0 0 30px; }
.brand-mark span { position: absolute; inset: 6px; border: 2px solid var(--cyan); border-radius: 50%; }
.brand-mark i { position: absolute; inset: 2px 12px; border: 1px solid var(--yellow); border-radius: 50%; transform: rotate(48deg); }
.brand-copy { min-width: 0; line-height: 1.05; flex: 1; }
.brand-copy b { display: block; font-size: 14px; letter-spacing: .02em; line-height: 1.15; }
.brand-copy small { display: block; color: var(--cyan); font-size: 14px; line-height: 1; letter-spacing: .08em; }

.icon-button, .sound-button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #0b1a26;
  border-radius: 4px;
  cursor: pointer;
}

.sound-button { min-width: 62px; font-size: 14px; }

.screen { min-height: 0; }
[hidden] { display: none !important; }

.start-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, .8fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: clamp(8px, 2vw, 22px);
  align-items: center;
  padding: clamp(12px, 3vh, 30px) clamp(8px, 3vw, 30px);
}

.start-copy h1 { margin: 5px 0 10px; font-size: clamp(30px, 6vw, 65px); line-height: .98; letter-spacing: -.06em; }
.start-copy h1 em { color: var(--yellow); font-style: normal; }
.start-copy > p:last-child { max-width: 36em; margin: 0; color: #c0d2dc; font-size: clamp(14px, 2vw, 17px); line-height: 1.65; }
.eyebrow { margin: 0; color: var(--cyan); font-size: 14px; font-weight: 700; letter-spacing: .08em; }

.orbit-poster { min-height: 250px; align-self: stretch; position: relative; overflow: clip; border: 1px solid var(--line); clip-path: polygon(9% 0, 100% 0, 100% 87%, 88% 100%, 0 100%, 0 11%); background: #081b29; }
.poster-grid { position: absolute; inset: 0; background-image: linear-gradient(rgba(88,227,211,.08) 1px, transparent 1px), linear-gradient(90deg, rgba(88,227,211,.08) 1px, transparent 1px); background-size: 30px 30px; }
.poster-planet { position: absolute; width: 66px; height: 66px; display: grid; place-items: center; border: 1px solid var(--cyan); border-radius: 50%; font-weight: 800; color: var(--cyan); box-shadow: 0 0 0 10px rgba(88,227,211,.05); }
.poster-planet.p1 { left: 14%; top: 20%; }
.poster-planet.p2 { right: 12%; bottom: 18%; border-color: var(--violet); color: var(--violet); box-shadow: 0 0 0 10px rgba(156,140,255,.05); }
.poster-word { position: absolute; left: 42%; top: 48%; transform: translate(-50%, -50%) rotate(-5deg); padding: 10px 16px; background: var(--yellow); color: #17202a; font-weight: 900; font-size: 19px; box-shadow: 10px 10px 0 rgba(255,114,94,.28); }
.poster-trail { position: absolute; width: 65%; height: 40%; left: 23%; top: 31%; border: 2px dashed rgba(255,209,102,.65); border-left-color: transparent; border-radius: 50%; transform: rotate(14deg); }

.start-actions { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr minmax(180px, 310px); align-items: center; gap: 8px 16px; }
.start-actions > small { grid-column: 2; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.25; }
.micro-guide { display: flex; flex-wrap: wrap; gap: 4px 12px; color: #b9cbd6; font-size: 14px; line-height: 1.25; }

.primary-button, .secondary-button {
  min-height: 48px;
  border: 0;
  border-radius: 3px;
  padding: 10px 18px;
  font-weight: 800;
  cursor: pointer;
}
.primary-button { background: var(--yellow); color: #10202b; box-shadow: 5px 5px 0 rgba(255,114,94,.6); }
.secondary-button { color: var(--ink); background: transparent; border: 1px solid var(--line); }

.game-screen {
  display: grid;
  grid-template-rows: auto auto minmax(207px, 1fr) auto auto;
  gap: 5px;
  padding: 5px 0 7px;
}

.hud-strip { display: grid; grid-template-columns: repeat(4, 1fr); background: #081925; border-block: 1px solid #1f4357; }
.hud-strip > div { min-width: 0; display: flex; align-items: baseline; justify-content: center; gap: 4px; padding: 5px 2px; border-right: 1px solid #1f4357; }
.hud-strip > div:last-child { border-right: 0; }
.hud-strip small { color: var(--muted); font-size: 14px; white-space: nowrap; }
.hud-strip b { color: var(--yellow); font-size: 15px; white-space: nowrap; }

.context-ribbon { min-height: 68px; padding: 6px 10px; border-left: 4px solid var(--yellow); background: #102331; }
.context-ribbon p { margin: 0 0 3px; font-size: clamp(15px, 2.7vw, 18px); font-weight: 700; line-height: 1.45; }
.context-ribbon mark { margin: 0 3px; padding: 1px 4px; background: var(--yellow); color: #15202a; }
.context-ribbon small { display: block; color: #b7cbd7; font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }

.space-world { min-height: 207px; position: relative; display: grid; grid-template-rows: auto 4px minmax(0, 1fr); overflow: clip; border: 1px solid #183b4e; background: #071823; }
.space-world::before { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(circle at 12% 72%, rgba(88,227,211,.18), transparent 17%), radial-gradient(circle at 86% 16%, rgba(156,140,255,.13), transparent 22%); }
.ambiguity-cloud { position: absolute; right: -16%; top: -30%; width: 48%; aspect-ratio: 1; border-radius: 50%; pointer-events: none; background: radial-gradient(circle, rgba(255,114,94,.3), transparent 66%); opacity: .2; transition: opacity .25s, transform .25s; }
.space-world.danger .ambiguity-cloud { opacity: .9; transform: translate(-15%, 15%) scale(1.3); }
.space-world.success-release::after { content: "受信成功"; position: absolute; z-index: 8; inset: 37% auto auto 50%; transform: translate(-50%, -50%); color: #071823; background: var(--cyan); padding: 8px 18px; font-size: clamp(18px, 4vw, 27px); font-weight: 900; letter-spacing: .08em; animation: release .65s ease-out both; }
@keyframes release { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.65); } 35% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); } 100% { opacity: 0; transform: translate(-50%, -50%) scale(1); } }
.danger-row { z-index: 2; display: flex; justify-content: space-between; padding: 2px 8px; color: #bcd0dc; font-size: 14px; line-height: 1.2; }
.space-world.danger .danger-row { color: #ffd5ce; font-weight: 700; }
.danger-track { z-index: 2; margin: 0 8px; background: #173344; overflow: clip; }
.danger-track i { display: block; width: 18%; height: 100%; background: var(--coral); transition: width .3s; }

.meaning-map { min-height: 181px; padding: 3px 7px 18px; position: relative; }
.map-surface { position: relative; width: 100%; height: 100%; min-height: 160px; overflow: clip; border: 1px solid #3e6578; background-image: linear-gradient(rgba(88,227,211,.08) 1px, transparent 1px), linear-gradient(90deg, rgba(88,227,211,.08) 1px, transparent 1px); background-size: 22px 22px; touch-action: pan-y; }
.map-cross::before, .map-cross::after { content: ""; position: absolute; background: rgba(255,255,255,.18); }
.map-cross::before { width: 1px; height: 100%; left: 50%; top: 0; }
.map-cross::after { width: 100%; height: 1px; top: 50%; left: 0; }
.axis-label { position: absolute; z-index: 1; color: #b5c9d5; font-size: 14px; line-height: 1; pointer-events: none; }
.axis-left { left: 5px; top: 50%; transform: translateY(-50%); }
.axis-right { right: 5px; top: 50%; transform: translateY(-50%); }
.axis-top { left: 50%; top: 5px; transform: translateX(-50%); }
.axis-bottom { left: 50%; bottom: 5px; transform: translateX(-50%); }
.meaning-probe { position: absolute; z-index: 5; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px; border: 2px solid #fff3b2; border-radius: 50% 50% 50% 12%; color: #18202a; background: var(--yellow); box-shadow: 0 0 0 7px rgba(255,209,102,.12), 5px 6px 0 rgba(0,0,0,.22); cursor: grab; touch-action: none; transition: box-shadow .15s; }
.meaning-probe:active { cursor: grabbing; box-shadow: 0 0 0 10px rgba(255,209,102,.16); }
.meaning-probe span { font-size: 16px; font-weight: 900; }
.target-reticle { position: absolute; z-index: 4; width: 58px; height: 58px; margin: -29px; border: 3px dashed var(--cyan); border-radius: 50%; pointer-events: none; animation: target-pulse 1.1s ease-in-out infinite; }
@keyframes target-pulse { 50% { transform: scale(.85); opacity: .55; } }
.coordinate-readout { position: absolute; left: 50%; bottom: 1px; transform: translateX(-50%); color: #c5d7e1; font-size: 14px; line-height: 1.2; white-space: nowrap; }

.feedback-line { min-height: 34px; display: flex; align-items: center; padding: 3px 8px; color: #c5d7e1; background: #0d202d; border-left: 3px solid var(--cyan); font-size: 14px; line-height: 1.25; overflow-wrap: anywhere; }
.control-deck { display: grid; grid-template-columns: 1fr 1fr 1.08fr; gap: 5px; }
.control-deck button { min-width: 0; min-height: 52px; padding: 3px; border: 1px solid #35566a; border-radius: 3px; color: var(--ink); background: #0c1f2c; font-weight: 700; font-size: 14px; line-height: 1.05; cursor: pointer; overflow-wrap: anywhere; }
.control-deck button span, .control-deck button small { display: block; }
.control-deck button small { color: var(--muted); font-size: 14px; margin-top: 1px; }
.control-deck button.transmit { color: #12212a; background: var(--yellow); border-color: var(--yellow); font-size: 14px; }
.control-deck button:disabled { opacity: .45; cursor: default; }

.quiz-screen { position: relative; display: grid; grid-template-rows: auto auto minmax(0, auto) auto auto; gap: 7px; align-content: center; padding: 10px clamp(8px, 4vw, 38px); }
.quiz-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 14px; }
.quiz-header b { color: var(--cyan); }
.quiz-planet { justify-self: center; width: 54px; height: 54px; display: grid; place-items: center; border: 2px solid var(--violet); border-radius: 50%; color: var(--violet); font-size: 22px; font-weight: 900; box-shadow: 0 0 0 8px rgba(156,140,255,.08); }
.quiz-screen h2 { margin: 0; text-align: center; font-size: clamp(17px, 4vw, 24px); line-height: 1.35; }
.quiz-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.quiz-choice { min-height: 48px; border: 1px solid #36556a; border-radius: 3px; color: var(--ink); background: #102431; padding: 7px; font-size: 14px; cursor: pointer; }
.quiz-choice.correct { color: #071823; background: var(--cyan); border-color: var(--cyan); font-weight: 800; }
.quiz-choice.wrong { color: #fff; background: #7d332f; border-color: var(--coral); text-decoration: line-through; }
.quiz-feedback { min-height: 46px; margin: 0; padding: 7px; border-left: 3px solid var(--yellow); background: #0e202c; font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }
.quiz-next { justify-self: center; width: min(100%, 280px); }

.result-screen { display: grid; grid-template-rows: auto auto auto auto auto; align-content: center; justify-items: center; gap: 8px; padding: 10px clamp(12px, 5vw, 50px); text-align: center; }
.result-orbit { position: relative; width: 90px; height: 90px; display: grid; place-items: center; }
.result-orbit span { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%; color: #11212b; background: var(--cyan); font-size: 22px; font-weight: 900; }
.result-orbit i, .result-orbit b { position: absolute; inset: 2px; border: 1px dashed var(--yellow); border-radius: 50%; transform: rotate(22deg); }
.result-orbit b { inset: 14px -9px; border-color: var(--violet); transform: rotate(-35deg); }
.result-screen h2 { margin: 0; font-size: clamp(21px, 5vw, 34px); }
.result-screen h2 strong { color: var(--yellow); }
.result-stats { width: min(100%, 420px); display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); }
.result-stats div { padding: 8px; }
.result-stats div + div { border-left: 1px solid var(--line); }
.result-stats small, .result-stats b { display: block; }
.result-stats small { color: var(--muted); font-size: 14px; }
.result-stats b { color: var(--cyan); font-size: 21px; }
.result-screen > p:not(.eyebrow) { max-width: 42em; margin: 0; color: #c1d1da; font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.result-actions { width: min(100%, 420px); display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }

.info-dialog { width: min(calc(100% - 24px), 620px); max-height: 82vh; overflow: auto; border: 1px solid var(--line); border-radius: 3px; color: var(--ink); background: #0b1d29; padding: 20px; }
.info-dialog::backdrop { background: rgba(1,8,14,.82); }
.info-dialog h2 { margin: 0 45px 10px 0; color: var(--yellow); }
.info-dialog li, .info-dialog p { font-size: 14px; line-height: 1.65; }
.dialog-close { position: absolute; right: 8px; top: 8px; width: 44px; height: 44px; border: 1px solid var(--line); color: var(--ink); background: #102431; cursor: pointer; }

@media (max-width: 560px) {
  .topbar { gap: 4px; }
  .brand-copy small { display: none; }
  .start-screen { grid-template-columns: 1fr; grid-template-rows: auto minmax(105px, 1fr) auto; padding: 6px 4px; gap: 6px; }
  .start-copy h1 { font-size: clamp(27px, 9vw, 40px); margin: 2px 0 5px; }
  .start-copy > p:last-child { font-size: 14px; line-height: 1.35; }
  .orbit-poster { min-height: 105px; }
  .poster-planet { width: 50px; height: 50px; }
  .poster-word { font-size: 16px; padding: 7px 11px; }
  .start-actions { grid-template-columns: 1fr; }
  .start-actions > small { grid-column: 1; }
  .micro-guide { justify-content: center; font-size: 14px; }
  .game-screen { grid-template-rows: auto auto minmax(207px, 1fr) auto auto; gap: 4px; padding: 4px 0; }
  .hud-strip small { display: block; font-size: 14px; }
  .hud-strip > div { display: block; text-align: center; padding: 3px 1px; }
  .hud-strip b { font-size: 14px; }
  .context-ribbon { min-height: 0; padding: 3px 7px; }
  .context-ribbon p { font-size: 15px; line-height: 1.35; }
  .context-ribbon small { font-size: 14px; }
  .feedback-line { font-size: 14px; min-height: 34px; }
  .control-deck { gap: 3px; }
  .quiz-screen { padding: 6px 4px; gap: 5px; }
  .quiz-planet { width: 44px; height: 44px; font-size: 18px; }
  .quiz-screen h2 { font-size: 17px; }
  .quiz-choices { gap: 5px; }
  .quiz-choice { min-height: 44px; font-size: 14px; padding: 4px; }
  .quiz-feedback { min-height: 44px; font-size: 14px; padding: 5px; }
  .result-orbit { width: 68px; height: 68px; }
  .result-screen { gap: 5px; padding: 6px 4px; }
}

@media (max-height: 590px) and (min-width: 561px) {
  .start-screen { padding-block: 7px; }
  .orbit-poster { min-height: 180px; }
  .start-copy h1 { font-size: 39px; }
  .game-screen { grid-template-rows: auto auto minmax(207px, 1fr) auto auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
