:root {
  --bg: #0c1222;
  --panel: #141c33;
  --line: #27314f;
  --text: #e9eefb;
  --muted: #97a3c2;
  --accent: #ffc857;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: "BIZ UDPGothic", "Hiragino Maru Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  line-height: 1.6;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 28px;
  align-items: center;
  max-width: 1320px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px 24px;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
}

.board-wrap {
  width: min(100%, calc(100vh - 32px));
  aspect-ratio: 1;
  overflow: hidden;   /* 窓を拡大したときも、丸い形のまま見せる */
  border-radius: 50%;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
}
#board.dragging { cursor: grabbing; }

.status {
  position: absolute;
  margin: 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(10, 17, 48, .85);
  color: var(--text);
  font-size: 14px;
  pointer-events: none;
}
.status[hidden] { display: none; }

/* ---------- 操作パネル ---------- */

.panel {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.panel h1 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: .04em;
}
.tag {
  margin-left: 6px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  vertical-align: middle;
}

.readout {
  margin: 0 0 16px;
  color: var(--accent);
  font-size: 27px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
/* 回っている間に月日や時刻のけた数が変わっても、行が折り返したり横にずれたりしないよう、
   月日・時刻を決まったはばの列に置き、「ごろの空」は次の行に置く */
.readout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 6px;
}
.readout span { white-space: nowrap; }
.readout .unit {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}

.field {
  display: grid;
  grid-template-columns: 3em 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.field-name { color: var(--muted); font-size: 13px; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }

button {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #1c2747;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
button:hover { background: #243158; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button:disabled { opacity: .5; cursor: default; }
button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #2a1e00;
  font-size: 16px;
  font-weight: 700;
}
button.primary:hover:not(:disabled) { background: #ffd57a; }

[hidden] { display: none !important; }

/* 早見盤 / ルーレットの切りかえ */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 14px;
  padding: 4px;
  border-radius: 12px;
  background: #0f1730;
}
.tabs button {
  margin: 0;
  padding: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
}
.tabs button[aria-selected="true"],
.tabs button[aria-checked="true"] {
  background: #26345f;
  color: var(--text);
  font-weight: 700;
}

/* 星のむずかしさ */
.tabs.three { grid-template-columns: repeat(3, 1fr); margin-bottom: 6px; }
.tabs.three button { padding: 7px 2px; font-size: 13px; }
.levels-name { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.level-note { margin: 0 0 14px; color: var(--muted); font-size: 12px; }

/* ルーレット */
.score { margin: 0 0 8px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.score b { color: var(--text); font-size: 20px; font-variant-numeric: tabular-nums; }
/* 問題文と 4択は、中身が変わってもパネルの高さが変わらないよう、場所を先に取っておく。
   (高さが変わると、たて方向の中央ぞろえでパネル全体が上下に動いてしまう) */
.prompt {
  min-height: calc(4.8em + 24px);   /* 3行ぶん */
  margin: 0 0 12px;
  padding: 12px;
  border-radius: 10px;
  background: #0f1730;
  font-size: 15px;
}
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: 52px;
  gap: 8px;
  min-height: 112px;                /* ボタン 2段ぶん */
  margin-bottom: 12px;
}
.choices.empty { visibility: hidden; }
.choices button {
  margin: 0;
  padding: 4px 6px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
}
.choices button.long { font-size: 12.5px; }   /* 長い名前は小さい字で 2行まで */
.choices button.right { border-color: #39a876; background: #1f6b47; color: #fff; opacity: 1; }
.choices button.wrong { border-color: #c25555; background: #7a2c2c; color: #fff; opacity: 1; }

.toggles {
  display: grid;
  gap: 6px;
  margin: 18px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
}
.toggles legend { padding: 0 6px; color: var(--muted); font-size: 12px; }
.toggles label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.toggles input { accent-color: var(--accent); }

.info {
  min-height: 3.2em;
  margin: 16px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #0f1730;
  font-size: 14px;
}
.info strong { color: var(--accent); font-size: 17px; }

.note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
}

/* ---------- 高さの低いPC画面 ---------- */
/* ルーレットのパネルは 4択の場所を先に取るぶん高いので、画面からはみ出さないよう見出しと注記をかくす */
@media (min-width: 861px) and (max-height: 760px) {
  .game-mode .panel h1,
  .game-mode .note { display: none; }
}

/* ---------- スマホ・タブレットのたて向き ---------- */
/* 盤を上、操作を下にならべる。ルーレットでは、盤・問題・4択・「まわす」が 1画面に収まるようにつめる。 */
@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 8px;
    align-items: start;
    min-height: 0;
    padding: 8px 12px 16px;
  }
  .board-wrap { width: min(100%, calc(100vh - 24px)); }
  /* ルーレット:操作に使う高さ(--controls)をのこして、盤をできるだけ大きくする。
     問題が出ている間も盤の大きさが変わらないよう、いちばん高くなるときの高さを引いている。 */
  .game-mode .board-wrap {
    --controls: 366px;
    width: clamp(220px, calc(100vh - var(--controls)), 100%);
    width: clamp(220px, calc(100dvh - var(--controls)), 100%);
  }

  /* パネルは 2列の格子にして、月日・時刻と点数を横にならべる */
  .panel {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    column-gap: 10px;
    padding: 10px 12px 12px;
    border-radius: 12px;
  }
  .panel > *,
  #gamePanel > * { grid-column: 1 / -1; }
  #gamePanel:not([hidden]) { display: contents; }
  .panel h1 { display: none; }

  .panel > .tabs { order: 1; margin-bottom: 8px; padding: 3px; }
  .tabs button { padding: 5px 6px; font-size: 13px; }
  .readout {
    order: 2;
    grid-column: 1;
    grid-template-columns: 4.8em 4.8em;   /* 月日と時刻を 1行に。点数と横にならべるので「ごろの空」は出さない */
    column-gap: 4px;
    justify-content: start;
    margin: 0 0 6px;
    font-size: 17px;
  }
  .readout .unit { display: none; }
  #gamePanel > .score { order: 3; grid-column: 2; margin: 0 0 6px; }
  .score b { font-size: 18px; }
  #explorePanel,
  .levels { order: 4; }
  .prompt { order: 5; }
  .choices { order: 6; }
  #spinBtn { order: 7; }
  .note { order: 8; margin-top: 10px; }

  /* 星のむずかしさ:見出しとボタンを 1行にならべる(範囲の説明は場所がないので出さない) */
  .levels {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 8px;
    align-items: center;
    margin-bottom: 8px;
  }
  .levels-name { margin: 0; }
  .level-note { display: none; }
  .levels .tabs { margin: 0; padding: 3px; }
  .tabs.three button { padding: 4px 2px; }

  .prompt {
    min-height: 58px;   /* 2行ぶん。行数が変わっても下のボタンが動きにくいようにする */
    margin-bottom: 8px;
    padding: 8px 10px;
    font-size: 14px;
    line-height: 1.5;
  }
  .choices { grid-auto-rows: 44px; gap: 6px; min-height: 94px; margin-bottom: 8px; }
  .choices button { padding: 3px 4px; font-size: 14px; }
  .choices button.long { font-size: 12px; }
  button.primary { margin-top: 0; padding: 9px; font-size: 15px; }
}

/* ---------- 盤(SVG) ---------- */

#board text {
  text-anchor: middle;
  dominant-baseline: central;
}

/* 星座盤:月日の目盛り */
.date-ring { fill: #f1e8d2; stroke: #8f8468; stroke-width: 1.5; }
.month-band { fill: #e4d9bb; }
.date-tick { fill: none; stroke: #3d4259; stroke-width: 1; }
.date-tick.month { stroke-width: 1.8; }
.day-num { fill: #4d5269; font-size: 12px; }
.month-name { fill: #22273c; font-size: 21px; font-weight: 700; }

/* 星座盤:星図 */
.sky { fill: url(#skyGrad); }
.equator { fill: none; stroke: #7f95d6; stroke-opacity: .35; stroke-width: 1; stroke-dasharray: 2 6; }
.ecliptic { fill: none; stroke: #e6c36a; stroke-opacity: .4; stroke-width: 1; stroke-dasharray: 7 6; }
.con-lines {
  fill: none;
  stroke: #86a0e6;
  stroke-opacity: .6;
  stroke-width: 1.15;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.star-glow { fill: #cfdcff; fill-opacity: .16; }

.con-label,
.star-label,
.pick-label {
  paint-order: stroke;
  stroke: #0a1130;
  stroke-width: 3.5px;
  stroke-opacity: .75;
  stroke-linejoin: round;
}
/* 文字の大きさ(--fs)は画面の大きさに合わせて app.js が決める */
.con-label,
.star-label,
.pick-label { font-size: calc(var(--fs, 15) * 1px); }
.con-label { fill: #aebff2; }
#board .star-label,
#board .pick-label {
  text-anchor: start;
  font-weight: 700;
}
.star-label { fill: #ffdc8f; }
.pick-label { fill: #ffffff; }
#board .pick-label.center { text-anchor: middle; }

/* ルーレットで出題中の星座 */
.con-highlight {
  fill: none;
  stroke: #ffd54a;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.con-highlight.pulse { animation: glow 1s ease-in-out infinite; }
@keyframes glow {
  0%, 100% { stroke-opacity: 1; }
  50% { stroke-opacity: .35; }
}
.pick-ring { fill: none; stroke: #ff6a5c; stroke-width: 2.2; }
/* ルーレットで出題中の星 */
.game .pick-ring { stroke: #ffd54a; stroke-width: 3; }
.pick-ring.pulse {
  transform-box: fill-box;
  transform-origin: center;
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.6); }
}
@media (prefers-reduced-motion: reduce) {
  .pick-ring.pulse,
  .con-highlight.pulse { animation: none; }
}

.hide-lines .con-lines { display: none; }

/* 地平盤:窓と時刻の目盛り */
.mask-body { fill: #2f4a86; }
.see-through .mask-body { fill-opacity: .45; }
.mask-rim { fill: none; stroke: #1b2c57; stroke-width: 1.5; }
.window-edge { fill: none; stroke: #e3eafc; stroke-width: 1.6; }
.time-tick { fill: none; stroke: #e8eefc; stroke-width: 1.1; }
/* 窓を拡大している間は、はしに少しだけ見える時刻の目盛りをかくす */
.hour-label,
.time-tick { transition: opacity .3s; }
.zoomed .hour-label,
.zoomed .time-tick { opacity: 0; }
.hour-label { fill: #ffffff; font-size: 16px; font-weight: 700; }
.hour-label.day { fill-opacity: .55; }
.dir { fill: #ffe9a8; font-size: 19px; font-weight: 700; }
.dir.minor { font-size: 13px; fill-opacity: .85; }
.zenith { fill: none; stroke: #ffffff; stroke-opacity: .55; stroke-width: 1.2; }
#board .zenith-label { text-anchor: start; fill: #ffffff; fill-opacity: .55; font-size: 12px; }
.mask-note { fill: #dfe7fb; fill-opacity: .7; font-size: 14px; }

/* 選んだ月日を指す印 */
.marker path { fill: #ff5a4d; stroke: #5a0f0a; stroke-width: 1; }
.marker line { stroke: #ff5a4d; stroke-width: 2.4; }
