:root {
  --ink: #f0f6ff;
  --ink-dim: rgba(240, 246, 255, 0.68);
  --glass: rgba(28, 18, 44, 0.3);
  --line: rgba(240, 246, 255, 0.22);
  --accent: #ffe6b8;
  --serif: "Shippori Mincho", "Hiragino Mincho ProN", serif;
  --sans: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0a1224; color: var(--ink); font-family: var(--sans); }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#scene:active { cursor: grabbing; }

#overlay {
  position: fixed; inset: 0; display: grid; place-items: safe center; padding: 16px; overflow-y: auto; z-index: 2;
  background: radial-gradient(ellipse at 50% 55%, rgba(10, 14, 36, 0), rgba(6, 8, 22, 0.3));
  transition: opacity 1.2s ease, visibility 1.2s;
}
#overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.panel {
  width: min(520px, 100%); padding: 36px 32px 28px; text-align: center;
  background: var(--glass); border: 1px solid var(--line); border-radius: 28px;
  backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.eyebrow { margin: 0 0 10px; font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-dim); }
h1 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: clamp(44px, 11vw, 68px); letter-spacing: 0.12em; text-shadow: 0 0 32px rgba(255, 230, 184, 0.45); }
.kana { margin: 2px 0 16px; font-size: 13px; letter-spacing: 0.5em; color: var(--ink-dim); }
.lead { margin: 0 0 22px; font-family: var(--serif); font-size: 15px; line-height: 2; color: var(--ink); }

.loading { height: 2px; margin: 0 auto 22px; width: 60%; background: rgba(255, 255, 255, 0.1); border-radius: 2px; overflow: hidden; transition: opacity 0.6s; }
#loading-bar { height: 100%; background: linear-gradient(90deg, #ffe6b8, #b8fff4); transform: scaleX(0); transform-origin: left; transition: transform 0.4s; }
#overlay.ready .loading { opacity: 0; }

.actions { display: grid; gap: 10px; }
button {
  font: inherit; color: var(--ink); cursor: pointer; border-radius: 16px; padding: 14px 18px;
  background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line);
  transition: background 0.3s, transform 0.2s, opacity 0.3s;
}
button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.14); }
button:active:not(:disabled) { transform: scale(0.98); }
button:disabled { opacity: 0.45; cursor: default; }
button small { display: block; margin-top: 3px; font-size: 11px; color: var(--ink-dim); }
button.primary { background: linear-gradient(135deg, rgba(255, 214, 160, 0.32), rgba(184, 255, 244, 0.22)); border-color: rgba(255, 230, 184, 0.5); font-size: 17px; }
button.ghost { background: transparent; }
#overlay:not(.ready) .actions button { opacity: 0.35; pointer-events: none; }

.pause-label, .pause-only { display: none; }
#overlay[data-mode="pause"] .start-label { display: none; }
#overlay[data-mode="pause"] .pause-label { display: inline; }
#overlay[data-mode="pause"] .pause-only { display: block; }

.settings { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin: 20px 0 6px; font-size: 13px; color: var(--ink-dim); }
.settings label { display: flex; align-items: center; gap: 8px; }
input[type="range"] { width: 110px; accent-color: #ffe6b8; }
select { font: inherit; font-size: 13px; color: var(--ink); background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-radius: 10px; padding: 4px 8px; }
select option { color: #111; }
.hint { margin: 14px 0 0; font-size: 11.5px; line-height: 1.8; color: var(--ink-dim); }

#end {
  position: fixed; left: 50%; bottom: 12vh; transform: translateX(-50%); text-align: center; width: min(520px, calc(100% - 32px));
  opacity: 0; visibility: hidden; transition: opacity 3s ease, visibility 3s;
}
#end.show { opacity: 1; visibility: visible; }
.end-title { margin: 0; font-family: var(--serif); font-size: 30px; letter-spacing: 0.2em; text-shadow: 0 0 24px rgba(240, 246, 255, 0.5); }
.end-sub { margin: 10px 0 18px; font-size: 13px; color: var(--ink-dim); }

#btn-pause {
  position: fixed; top: max(14px, env(safe-area-inset-top)); right: 14px; width: 44px; height: 44px; padding: 0;
  border-radius: 50%; font-size: 13px; background: rgba(10, 14, 36, 0.3); opacity: 0.5;
}
#btn-pause:hover { opacity: 1; }
#hud { position: fixed; left: 8px; top: 8px; margin: 0; padding: 6px 10px; font: 11px/1.5 ui-monospace, monospace; background: rgba(0, 0, 0, 0.55); border-radius: 8px; pointer-events: none; white-space: pre; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 10px 16px; border-radius: 12px; background: rgba(0, 0, 0, 0.7); font-size: 13px; opacity: 0; transition: opacity 0.4s; pointer-events: none; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }

@media (max-width: 480px) {
  .panel { padding: 28px 20px 22px; border-radius: 22px; }
  .lead { font-size: 14px; }
}

/* 開始・一時停止画面を開いている間は完了表示を隠す（重なって押せなくなるのを防ぐ） */
body.overlay-open #end { visibility: hidden; opacity: 0; transition: none; }

/* 横向きのスマホなど背の低い画面 */
@media (max-height: 560px) {
  .panel { padding: 18px 20px 16px; }
  h1 { font-size: 38px; }
  .kana { margin-bottom: 8px; }
  .lead, .hint, .eyebrow { display: none; }
  .loading { margin-bottom: 12px; }
  .actions { grid-template-columns: 1fr 1fr; }
  .actions .pause-only { grid-column: 1 / -1; }
  .settings { margin-top: 12px; }
}
