:root {
  --bg: #0b0d14;
  --panel: rgba(18, 22, 36, .82);
  --line: rgba(255, 255, 255, .3);
  --text: #e8ecff;
  --muted: #8b93b5;
  --r: #ff4d5a;
  --g: #4dff7a;
  --b: #4d86ff;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

#stage { position: fixed; inset: 0; touch-action: none; }
#stage canvas { display: block; touch-action: none; }

/* ---------- HUD（問題文） ---------- */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  padding: calc(14px + var(--safe-t)) 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  z-index: 5;
}
/* 右上のボタン */
#hud { gap: 8px; }
.hud-btns {
  align-self: flex-end;
  display: flex;
  gap: 8px;
  position: relative;
  z-index: 7;
  pointer-events: auto;
}
.chip {
  pointer-events: auto;
  touch-action: manipulation;
}

#question {
  margin: 0;
  margin-top: 8px;
  padding-left: .35em;               /* letter-spacing の右ズレ補正 */
  font-size: clamp(24px, 6vw, 38px);
  letter-spacing: .14em;
  color: #fff;
  text-shadow: 0 0 8px rgba(255, 255, 255, .3), 0 0 16px rgba(255, 255, 255, .25);
  cursor: default;
  white-space: pre;
}
.hud-sub { display: flex; align-items: center; gap: 8px; }
.chip {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.chip:active { transform: scale(.96); }

#hint {
  margin: 0;
  margin-top: 16px;
  padding-left: .35em;               /* letter-spacing の右ズレ補正 */
  font-size: clamp(24px, 6vw, 38px);
  letter-spacing: .14em;
  color: #fff;
  text-shadow: 0 0 8px rgba(255, 255, 255, .55), 0 0 16px rgba(255, 255, 255, .25);
  cursor: default;
  white-space: pre;
}
.hud-sub { display: flex; align-items: center; gap: 8px; }
.chip {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.chip:active { transform: scale(.96); }

/* STEP2：「make」の e の上のランプ */
#question.s2 { margin-top: 8px; }                 /* ランプ分の余白 */
#question .has-lamps { position: relative; }
/* STEP2の「?」：黒枠白抜き＋色付き背景 */
.qbox {
  display: inline-block;
  width: 1.15em;
  height: 1.15em;
  line-height: 1.15em;
  margin-right: .12em;
  vertical-align: baseline;
  text-align: center;
  letter-spacing: 0;
  border-radius: 0em;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 0 12px rgba(255, 255, 255, .55), 0 0 2px var(--c);
  text-shadow:
    -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000,
    0 -2px 0 #000, 0 2px 0 #000, -2px 0 0 #000, 2px 0 0 #000;
}
.elamps {
  position: absolute;
  left: calc(49%);                         /* letter-spacing の分を補正 */
  bottom: 80%;
  transform: translateX(-50%);
  margin-bottom: 12px;
  display: flex;
  gap: 4px;
  pointer-events: none;
}
.elamps i {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #353b5c;
  border: 1px solid #8b93b5;
}
.elamps i.on {
  background: #fff;
  box-shadow: 0 0 8px #fff, 0 0 18px rgba(255, 255, 255, .65);
}

#hint.s2 { margin-top: 12px; }                 /* ランプ分の余白 */
#hint .has-lamps { position: relative; }
.elamps-hint {
  position: absolute;
  left: calc(49%);                         /* letter-spacing の分を補正 */
  bottom: 80%;
  transform: translateX(-50%);
  margin-bottom: 12px;
  display: flex;
  gap: 4px;
  pointer-events: none;
}
.elamps-hint i {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #353b5c;
  border: 1px solid #8b93b5;
}
.elamps-hint i.on {
  background: #fff;
  box-shadow: 0 0 8px #fff, 0 0 18px rgba(255, 255, 255, .65);
}

/* 3つのランプ */
#lamps { display: flex; gap: 16px; }
#lamps i {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #353b5c;
  border: 2px solid #8b93b5;
  transition: background .3s, box-shadow .3s;
}
#lamps i.on {
  background: #fff;
  box-shadow: 0 0 10px #fff, 0 0 26px rgba(255, 255, 255, .65);
}

/* ---------- ダイアログ ---------- */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(5, 7, 12, .72);
  backdrop-filter: blur(6px);
  z-index: 20;
}
#stats { z-index: 30; }
.dialog {
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  overflow: auto;
  text-align: center;
  padding: 16px 16px;
  background: linear-gradient(160deg, rgba(30, 36, 62, .95), rgba(14, 17, 30, .95));
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
  animation: pop .35s ease-out;
}
.small-dialog { max-width: 340px; }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }

.dialog h1 { margin: 0 0 14px; font-size: 46px; letter-spacing: .14em; }
.dialog h2 { margin: 0 0 12px; font-size: 22px; }
.dialog p { line-height: 1.75; margin: 10px 0; font-size: 14px; }
.lead { font-size: 15px !important; }
.muted { color: var(--muted); }
.small { font-size: 12px !important; }
.glow { font-size: 34px !important; letter-spacing: .18em; color: #fff; text-shadow: 0 0 3px #fff, 0 0 16px rgba(255, 255, 255, .5); }

.btn {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 52px;
  padding: 12px 26px;
  margin-top: 10px;
  font-size: 16px; font-weight: 700;
  color: #0b0d14;
  background: linear-gradient(150deg, #fff, #ccc);
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  transition: transform .1s, filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.97); }
.btn small { font-size: 11px; font-weight: 500; opacity: .7; }
.btn.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
}

.row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

dl { display: grid; grid-template-columns: 1fr auto; gap: 10px 16px; margin: 16px 0; text-align: left; }
dt { color: var(--muted); font-size: 14px; }
dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }

@media (max-height: 480px) and (orientation: landscape) {
  .dialog { padding: 18px; }
  .dialog h1 { font-size: 34px; margin-bottom: 6px; }
  #hud { gap: 6px; padding-top: calc(8px + var(--safe-t)); }
}

/* ヒントダイアログ */
.hint-dialog { text-align: left; max-width: 480px; }
.hint-dialog h2 { text-align: center; }
.hgroup { margin: 14px 0; }
.hgroup h3 { margin: 0 0 8px; font-size: 15px; }
.hgroup h3::before { content: '■ '; color: var(--muted); }
.hgroup details {
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 6px;
  padding: 10px 12px;
}
.hgroup summary {
  cursor: pointer;
  list-style: none;
  font-size: 14px;
  font-weight: 600;
}
.hgroup summary::-webkit-details-marker { display: none; }
.hgroup summary::before { content: '▶ '; font-size: 11px; color: var(--muted); }
.hgroup details[open] summary::before { content: '▼ '; }
.hgroup details p { margin: 8px 0 0; font-size: 13px; line-height: 1.7; color: #cfd6ff; }
.hint-dialog .btn { display: flex; margin: 12px auto 0; }

#gradient-text {
  margin: 0;
  display: inline-block;
  /* グラデーションの色や方向を定義 */
  background: linear-gradient(135deg, rgb(77, 225, 255), rgb(255, 143, 199), rgb(255, 227, 107), rgb(255, 255, 255));
  
  /* 背景を文字の形に切り抜く */
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  
  /* Firefoxなどの標準プロパティ対応 */
  background-clip: text;
  color: transparent;

}

#answerbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(96px + var(--safe-b));
  width: min(440px, calc(100% - 24px));
  display: flex;
  gap: 10px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  backdrop-filter: blur(12px);
  z-index: 8;
}
#answerbar input {
  flex: 1;
  min-width: 0;
  padding: 0 14px;
  font-size: 16px;                 /* iOSの自動ズーム防止 */
  color: var(--text);
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
#answerbar input:focus { border-color: rgba(255, 255, 255, .45); }
#answerbar .btn { margin-top: 0; padding: 12px 22px; white-space: nowrap; }
#answerbar.shake { animation: shake .35s; }
@keyframes shake {
  20% { transform: translateX(calc(-50% - 8px)); }
  40% { transform: translateX(calc(-50% + 8px)); }
  60% { transform: translateX(calc(-50% - 5px)); }
  80% { transform: translateX(calc(-50% + 5px)); }
}