@import './presentation.css';
/* カメレオる：縦画面の iPhone Safari を主対象にした画面。比較面（壁・体・プレビュー）には色の効果をかけない。 */
:root {
  --bg: #14183a;
  --bg-2: #1d2350;
  --panel: #232a5e;
  --text: #f5f6ff;
  --muted: #b9bee6;
  --accent: #6aff4d;
  --accent-ink: #0f2a07;
  --danger: #ff5a5f;
  --warn: #ffcc4d;
  --line: rgba(255, 255, 255, 0.18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Hiragino Sans', 'Noto Sans', 'Noto Sans JP', 'Noto Sans Thai', 'Noto Sans Arabic', sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  overflow-x: hidden;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}

.screen {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

h1,
h2,
h3 {
  margin: 0.4em 0;
  line-height: 1.25;
}

.note {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ---------- ボタン ---------- */
.btn {
  display: block;
  width: 100%;
  min-height: 48px;
  margin: 8px 0;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  border-color: transparent;
}
.btn-danger {
  background: #3a1d2a;
  border-color: var(--danger);
}
.btn-small {
  display: inline-block;
  width: auto;
  min-height: 40px;
  margin: 4px 4px 4px 0;
  padding: 6px 12px;
  font-size: 0.9rem;
}
.btn-x {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  background: #000;
  color: #fff;
  border-color: #444;
  font-weight: 700;
}
.btn-back {
  margin-top: 20px;
}
.btn-skip {
  position: fixed;
  right: calc(12px + var(--safe-right));
  top: calc(12px + var(--safe-top));
  z-index: 60;
  width: auto;
  min-height: 40px;
}
.badge {
  display: inline-block;
  min-width: 1.6em;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--warn);
  color: #222;
  font-size: 0.8rem;
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ---------- ホーム ---------- */
.home-header {
  text-align: center;
}
.home-language {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
}
.home-language::after {
  content: '';
  border: 4px solid transparent;
  border-bottom: 0;
  border-top-color: currentColor;
}
.home-language .lang-select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.home-language:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.home-art {
  position: relative;
  margin: 0 auto;
}
.home-art-3d {
  width: min(100%, 300px);
  height: 190px;
  margin-top: 0;
}
.showcase-canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.title {
  font-size: 2.2rem;
  letter-spacing: 0.04em;
}
.subtitle {
  color: var(--muted);
  margin-top: 0;
}
.notices .notice {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
}
.notice-update {
  border-color: var(--warn) !important;
}
.notice-dev {
  border-style: dashed !important;
  color: var(--warn);
}
/* ---------- 名前 ---------- */
.name-field {
  margin: 12px 0;
  padding: 12px;
  border-radius: 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
}
.name-label {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}
.name-input {
  width: 100%;
  min-height: 46px;
  margin-top: 6px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0e1130;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* iOSの自動拡大を防ぐ */
}
.name-field.invalid .name-input {
  border-color: var(--danger);
}
.name-error {
  color: var(--danger);
  margin: 6px 0 0;
  min-height: 0;
}
.name-help,
.name-same,
.name-preview {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 6px 0 0;
  line-height: 1.45;
}
.user-text,
.name-preview-value {
  unicode-bidi: isolate;
  overflow-wrap: anywhere;
  color: var(--text);
}

/* ---------- 本編・練習 ---------- */
.screen.game {
  max-width: none;
  height: 100vh;
  height: 100dvh;
  padding: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
  touch-action: none;
}
.screen.practice {
  grid-template-rows: minmax(0, 1fr) auto auto;
}
.stage-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #0b0d22;
}
.stage {
  position: absolute;
  inset: 0;
}
.stage-canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.cover {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: #0b0d22; /* 不透明：停止中・再開準備中は壁の色を読めない */
}
.hud {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(6px + var(--safe-top)) calc(10px + var(--safe-right)) 6px calc(10px + var(--safe-left));
  background: linear-gradient(to bottom, rgba(10, 12, 30, 0.75), rgba(10, 12, 30, 0));
  pointer-events: none;
}
.hud button {
  pointer-events: auto;
}
.hud-left,
.hud-right {
  display: flex;
  flex-direction: column;
  font-weight: 700;
  font-size: 0.95rem;
  text-shadow: 0 1px 2px #000;
}
.hud-right {
  margin-left: auto;
  flex-direction: row;
}
.hud-buildings {
  font-size: 1.15rem;
}
.gauge {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.gauge-track {
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.4);
}
.gauge-fill {
  width: 100%;
  height: 100%;
  transform-origin: left center;
  transform: scaleX(0);
  background: #ffe066;
}
.gauge-fill[data-level='caution'] {
  background: #ff9f43;
}
.gauge-fill[data-level='danger'] {
  background: #ff4757;
}
.gauge-word {
  font-size: 0.8rem;
  white-space: nowrap;
  text-shadow: 0 1px 2px #000;
}
.btn-pause {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(20, 24, 58, 0.85);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
}
.switch-ok {
  position: absolute;
  z-index: 24;
  right: calc(12px + var(--safe-right));
  top: calc(60px + var(--safe-top));
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #14183a;
  font-weight: 800;
  pointer-events: none;
}
.match-word {
  position: absolute;
  z-index: 24;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(10, 12, 30, 0.7);
  font-weight: 700;
  pointer-events: none;
  white-space: nowrap;
}
.match-word:empty {
  display: none;
}
.match-word[data-state='success'] {
  color: var(--accent);
}
.match-word[data-state='slight'] {
  color: var(--warn);
}
.match-word[data-state='danger'] {
  color: #ff8a8a;
}
.banner-host {
  position: absolute;
  z-index: 26;
  left: 0;
  right: 0;
  top: calc(64px + var(--safe-top));
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

/* 操作部：位置とサイズは途中解放で変えない */
.controls {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 12px;
  align-items: center;
  height: min(42vh, 360px);
  height: min(42dvh, 360px);
  min-height: 230px;
  padding: 12px calc(12px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(12px + var(--safe-left));
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.controls.disabled .palette,
.controls.disabled .bar {
  filter: saturate(0.6) brightness(0.8);
}
.palette {
  position: relative;
  justify-self: center;
  width: min(100%, calc(min(42vh, 360px) - 24px - var(--safe-bottom)));
  width: min(100%, calc(min(42dvh, 360px) - 24px - var(--safe-bottom)));
  min-width: 180px;
  aspect-ratio: 1 / 1;
  max-height: 100%;
}
.palette-canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}
.marker {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}
.palette-marker {
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px #000, inset 0 0 0 2px #000;
}
.bar-wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.bar {
  position: relative;
  flex: 1;
  width: 52px;
  border-radius: 14px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}
.bar-fill {
  position: absolute;
  inset: 0;
  border-radius: 14px;
}
.bar-guide-range {
  position: absolute;
  right: 4px;
  width: 12px;
  border: 2px solid #cff7ff;
  border-radius: 4px;
  background: #29829c;
  box-shadow: 0 0 0 1px #081123;
  pointer-events: none;
}
.controls.disabled .bar-guide-range,
.controls.bar-locked .bar-guide-range {
  display: none;
}
.bar-marker {
  width: 64px;
  height: 14px;
  left: -6px;
  margin-top: -7px;
  border-radius: 7px;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px #000;
}
.bar-lock {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 14px;
  background: #6b6f80; /* 未開放は灰色 */
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
  writing-mode: horizontal-tb;
  pointer-events: none;
}
.controls.bar-locked .bar-marker {
  display: none;
}
.bar-hint {
  display: flex;
  flex-direction: column;
  font-size: 0.65rem;
  color: var(--muted);
  text-align: center;
}
.preview {
  position: absolute;
  left: calc(12px + var(--safe-left));
  top: 12px;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px #000;
  pointer-events: none; /* 入力を遮らない */
  z-index: 2;
}

/* ---------- 停止・カウントダウン・ダイアログ ---------- */
.layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}
.layer > * {
  pointer-events: auto;
}
.layer > .toast {
  pointer-events: none;
}
.pause-overlay,
.dialog-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  background: rgba(8, 10, 26, 0.86);
  z-index: 55;
  overflow-y: auto;
}
.pause-overlay {
  background: #0b0d22; /* 停止中は壁の色を読めない不透明な覆い */
}
.pause-panel,
.dialog {
  width: min(100%, 420px);
  max-height: 100%;
  overflow-y: auto;
  padding: 18px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.dialog-actions {
  margin-top: 12px;
}
.countdown {
  font-size: 6rem;
  font-weight: 800;
}
.guide-list li {
  margin: 6px 0;
  line-height: 1.5;
}
.setting-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
}
.setting-row span {
  flex: 0 0 auto;
  min-width: 6em;
}
.setting-row input[type='range'] {
  flex: 1;
}
.lang-select {
  flex: 1;
  min-height: 44px;
  font-size: 16px;
  border-radius: 10px;
}
.panel {
  margin: 14px 0;
  padding: 12px;
  border-radius: 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
}
.panel-title {
  font-size: 1.05rem;
}

/* ---------- お知らせ ---------- */
.toast {
  margin: 6px 12px;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(10, 12, 30, 0.88);
  border: 1px solid var(--line);
  font-weight: 700;
  text-align: center;
  max-width: calc(100vw - 24px);
  overflow-wrap: anywhere;
  transition: opacity 0.35s;
}
.layer > .toast {
  position: fixed;
  left: 50%;
  top: calc(16px + var(--safe-top));
  transform: translateX(-50%);
}
.toast-big {
  font-size: 1.15rem;
  background: rgba(255, 255, 255, 0.95);
  color: #14183a;
}
.toast-combo {
  color: var(--accent);
}
.toast-warn {
  border-color: var(--warn);
}
.toast-out {
  opacity: 0;
}

/* ---------- 結果 ---------- */
.result-title {
  text-align: center;
  font-size: 1.8rem;
}
.result-cleared {
  color: var(--accent);
}
.result-detected {
  color: #ff8a8a;
}
.result-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat {
  display: flex;
  flex-direction: column;
  padding: 10px;
  border-radius: 12px;
  background: var(--bg-2);
}
.stat-label {
  color: var(--muted);
  font-size: 0.85rem;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.breakdown {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-2);
}
.breakdown dt {
  color: var(--muted);
}
.breakdown dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.result-status {
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px dashed var(--line);
}

/* ---------- ランキング・記録 ---------- */
.rank-list {
  list-style: none;
  padding: 0;
  margin: 8px 0;
}
.rank-row {
  display: grid;
  grid-template-columns: 3.4em minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.rank-name {
  overflow-wrap: anywhere;
}
.rank-no,
.rank-buildings,
.rank-avg {
  white-space: nowrap;
  direction: ltr;
}
.ranking.loading {
  opacity: 0.7;
}
.records-list {
  list-style: none;
  padding: 0;
}
.record {
  padding: 10px;
  margin: 8px 0;
  border-radius: 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
}
.record-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-weight: 700;
}
.record-correction {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--warn);
}

/* ---------- 練習 ---------- */
.practice-actions {
  display: flex;
  gap: 8px;
  padding: 8px calc(12px + var(--safe-right)) 4px calc(12px + var(--safe-left));
  background: var(--bg-2);
}
.practice-actions .btn {
  margin: 0;
}
.practice-value {
  font-weight: 700;
  text-shadow: 0 1px 2px #000;
}
.practice-review {
  position: absolute;
  z-index: 30;
  left: 12px;
  right: 12px;
  bottom: 12px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(20, 24, 58, 0.95);
  border: 1px solid var(--line);
}
.swatches {
  display: flex;
  gap: 16px;
}
.swatch-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
}
.swatch {
  width: 72px;
  height: 48px;
  border-radius: 10px;
  border: 2px solid #fff;
}
.practice-table {
  width: 100%;
  border-collapse: collapse;
}
.practice-table th,
.practice-table td {
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.share-manual {
  width: 100%;
  font: inherit;
}

/* ---------- 仮の図形の舞台（WebGLがない時） ---------- */
.dom-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(#8fd3ff, #dff4ff);
}
.dom-wall {
  position: absolute;
  bottom: 18%;
  top: 22%;
  left: 0;
}
.dom-jewelry-shop {
  background: #efe0c7;
  border-top: 6px solid #584260;
}
.dom-shop-sign, .dom-shop-windows {
  position: absolute;
  left: 8%;
  width: 84%;
}
.dom-shop-sign {
  top: 10%;
  height: 18%;
  background: #58356f;
}
.dom-shop-sign::after, .dom-stolen-jewel {
  background: linear-gradient(125deg, #efffff 25%, #73e1ef 26% 64%, #1f829e 65%);
  clip-path: polygon(18% 0, 82% 0, 100% 35%, 50% 100%, 0 35%);
}
.dom-shop-sign::after {
  content: '';
  position: absolute;
  inset: 14% 32%;
}
.dom-shop-windows {
  bottom: 10%;
  height: 38%;
  border: 4px solid #724e41;
  background: linear-gradient(to right, transparent 47%, #724e41 47% 52%, transparent 52%),
    color-mix(in srgb, #bfedff, #ff4936 var(--alarm, 0%));
}
.dom-stolen-jewel {
  position: absolute;
  width: 16px;
  height: 15px;
  transform: translateX(-50%);
  pointer-events: none;
}
.dom-hero {
  position: absolute;
  left: 32%;
  /* 色の面は 58×74 のまま。輪郭の幅 --w（整数px）だけが段階で変わり、その分だけ外形と位置を補う。
     段階 8（--outline-w:3px、色 27 27 27）は従来の 64×80・3px・#1b1b1b と同じ。 */
  --w: var(--outline-w, 3px);
  width: calc(58px + 2 * var(--w));
  height: calc(74px + 2 * var(--w));
  margin-left: calc(-29px - var(--w));
  bottom: calc(18% + 3px - var(--w));
  border-radius: 45% 55% 40% 40%;
  border: var(--w) solid rgb(var(--outline-rgb, 27 27 27));
}
.dom-hero-eye {
  position: absolute;
  right: 8px;
  top: 10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: repeating-radial-gradient(circle, #fff 0 3px, #1b1b1b 3px 5px);
}
.dom-police {
  position: absolute;
  bottom: 18%;
  left: -80px;
  width: 40px;
  height: 90px;
  border-radius: 20px;
  background: #1f2f5c;
  transition: left 0.6s;
}
.dom-police.visible {
  left: 4%;
}

/* ---------- 見た目の仕上げ（動き・奥行き）。壁・体・プレビューの色には何も重ねない ---------- */
body {
  background: radial-gradient(120% 70% at 50% 0%, #26306e 0%, var(--bg) 60%) fixed, var(--bg);
}
.screen:not(.game) {
  animation: screen-in 0.28s ease-out both;
}
@keyframes screen-in {
  from {
    opacity: 0;
    translate: 0 10px;
  }
}
.btn {
  font-weight: 600;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}
.btn-primary {
  background: linear-gradient(#8dff6b, #4fe034);
  box-shadow: 0 4px 0 #2a8f17, inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.btn-primary:active:not(:disabled) {
  box-shadow: 0 1px 0 #2a8f17;
  transform: translateY(3px);
}

/* ホーム：夜の街の空、題字、ボタンの並び */
.screen.home {
  position: relative;
  overflow: hidden;
}
.home-sky {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 330px;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 18%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 31% 9%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 58% 14%, #cfe0ff 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 77% 7%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 90% 24%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 84% 20%, #fff6d8 0 15px, rgba(255, 246, 216, 0.25) 16px, transparent 34px),
    linear-gradient(#1b2358, #1b2358) 0% 100% / 13% 30% no-repeat,
    linear-gradient(#222b66, #222b66) 12% 100% / 10% 46% no-repeat,
    linear-gradient(#1b2358, #1b2358) 24% 100% / 15% 24% no-repeat,
    linear-gradient(#222b66, #222b66) 76% 100% / 14% 40% no-repeat,
    linear-gradient(#1b2358, #1b2358) 90% 100% / 11% 56% no-repeat,
    linear-gradient(#222b66, #222b66) 100% 100% / 9% 28% no-repeat,
    radial-gradient(60% 55% at 50% 62%, rgba(106, 255, 77, 0.2), transparent 70%);
  -webkit-mask-image: linear-gradient(#000 70%, transparent);
  mask-image: linear-gradient(#000 70%, transparent);
}
.home-header,
.screen.home > :not(.home-sky) {
  position: relative;
  z-index: 1;
}
.home-art-3d {
  width: min(100%, 320px);
  height: 210px;
}
.title {
  margin: 0;
  font-size: clamp(2.3rem, 11vw, 3.2rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: linear-gradient(#d9ff7a 10%, #6aff4d 55%, #1fc98a);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 #0c2a14) drop-shadow(0 0 14px rgba(106, 255, 77, 0.35));
  animation: title-in 0.6s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
@keyframes title-in {
  from {
    opacity: 0;
    scale: 0.7;
  }
}
.subtitle {
  font-weight: 600;
}
.btn-start {
  min-height: 60px;
  font-size: 1.25rem;
  letter-spacing: 0.08em;
  animation: start-pulse 1.8s ease-in-out infinite;
}
@keyframes start-pulse {
  50% {
    filter: brightness(1.12);
    box-shadow: 0 4px 0 #2a8f17, 0 0 0 6px rgba(106, 255, 77, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  }
}
.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}
.home-grid .btn {
  margin: 0;
  min-height: 54px;
  font-size: 0.95rem;
}
.home-grid .btn::before {
  margin-right: 6px;
}
.home-grid [data-testid='home-practice']::before {
  content: '🎨';
}
.home-grid [data-testid='home-ranking']::before {
  content: '🏆';
}
.home-grid [data-testid='home-howto']::before {
  content: '📖';
}
.home-grid [data-testid='home-settings']::before {
  content: '⚙️';
}
.home-grid [data-testid='home-records']::before {
  content: '📋';
}

/* 本編の上の表示 */
.hud {
  align-items: flex-start;
}
.hud-left {
  padding: 4px 10px 6px;
  border-radius: 14px;
  background: rgba(10, 12, 30, 0.66);
  border: 1px solid var(--line);
  min-width: 5.6em;
}
.hud-buildings {
  font-size: 1.2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transform-origin: left center;
}
.hud-progress {
  height: 4px;
  margin: 2px 0 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
}
.hud-progress-fill {
  width: 100%;
  height: 100%;
  background: var(--accent);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 0.4s ease-out;
}
.hud-score-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.hud-score {
  transform-origin: left center;
}
.hud-gain {
  color: var(--accent);
  opacity: 0;
}
.hud-gain.show {
  animation: gain-float 1.1s ease-out both;
}
@keyframes gain-float {
  0% {
    opacity: 0;
    translate: 0 6px;
  }
  15% {
    opacity: 1;
    translate: 0 0;
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    translate: 0 -8px;
  }
}
.bump {
  animation: bump 0.32s ease-out;
}
@keyframes bump {
  30% {
    scale: 1.22;
  }
}
.gauge {
  align-items: flex-start;
  padding: 5px 10px 4px 6px;
  border-radius: 14px;
  background: rgba(10, 12, 30, 0.66);
  border: 1px solid var(--line);
}
.gauge-icon {
  flex: 0 0 auto;
  font-size: 1.15rem;
  line-height: 1.3;
}
.gauge-icon::before {
  content: '🚨';
}
.gauge-icon.ring {
  animation: icon-ring 0.7s ease-out;
}
@keyframes icon-ring {
  0%,
  100% {
    rotate: 0deg;
    scale: 1;
  }
  15% {
    rotate: -18deg;
    scale: 1.5;
  }
  35% {
    rotate: 16deg;
    scale: 1.4;
  }
  55% {
    rotate: -10deg;
  }
  75% {
    rotate: 6deg;
  }
}
.gauge-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.gauge-track {
  position: relative;
  flex: none;
  height: 14px;
}
.gauge-fill {
  background: linear-gradient(#fff3a0, #ffd43b);
  transition: transform 0.12s linear;
}
.gauge-fill[data-level='caution'] {
  background: linear-gradient(#ffc078, #ff922b);
}
.gauge-fill[data-level='danger'] {
  background: linear-gradient(#ff8787, #f03e3e);
}
.gauge-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255, 255, 255, 0.55);
}
.gauge-mark-1 {
  left: 30%;
}
.gauge-mark-2 {
  left: 70%;
}
.gauge-word {
  font-size: 0.78rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud[data-level='caution'] .gauge-word {
  color: #ffc078;
}
.hud[data-level='danger'] .gauge-word {
  color: #ff8787;
}
.hud[data-level='danger'] .gauge {
  border-color: #ff6b6b;
  animation: gauge-alarm 0.7s ease-in-out infinite;
}
@keyframes gauge-alarm {
  50% {
    box-shadow: 0 0 0 3px rgba(255, 80, 80, 0.45);
    background: rgba(70, 12, 22, 0.8);
  }
}
.btn-pause {
  flex: 0 0 auto;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.switch-ok {
  top: calc(72px + var(--safe-top));
  border: 2px solid #14183a;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
  animation: switch-blink 0.5s ease-in-out infinite alternate;
}
@keyframes switch-blink {
  to {
    scale: 1.07;
  }
}
.match-word {
  padding: 5px 16px;
  border: 2px solid #0a0c1e;
  font-weight: 800;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.match-word[data-state='success'] {
  background: var(--accent);
  color: var(--accent-ink);
}
.match-word[data-state='slight'] {
  background: var(--warn);
  color: #3b2a00;
}
.match-word[data-state='danger'] {
  background: #f03e3e;
  color: #fff;
}
.match-word.pop {
  animation: word-pop 0.28s ease-out;
}
@keyframes word-pop {
  from {
    scale: 1.35;
  }
}
.banner-host {
  top: calc(78px + var(--safe-top));
}
.toast {
  animation: toast-in 0.26s cubic-bezier(0.2, 1.4, 0.4, 1) both;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}
@keyframes toast-in {
  from {
    opacity: 0;
    scale: 0.8;
  }
}
.toast-combo {
  font-size: 1.2rem;
  color: #14183a;
  background: linear-gradient(#d9ff7a, #6aff4d);
  border-color: #14183a;
}
.toast-big {
  border-color: #14183a;
}

/* 停止・再開 */
.pause-panel {
  animation: toast-in 0.24s cubic-bezier(0.2, 1.3, 0.4, 1) both;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.3);
}
.pause-panel h2,
.dialog-title {
  text-align: center;
}
.dialog {
  animation: toast-in 0.22s cubic-bezier(0.2, 1.3, 0.4, 1) both;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.3);
}
.countdown {
  font-size: 7rem;
  font-weight: 900;
  color: var(--accent);
  -webkit-text-stroke: 2px #0c2a14;
  text-shadow: 0 6px 0 #0c2a14;
}
.countdown.tick {
  animation: count-tick 0.9s ease-out both;
}
@keyframes count-tick {
  0% {
    scale: 1.9;
    opacity: 0;
  }
  18% {
    scale: 1;
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    scale: 0.85;
    opacity: 0.5;
  }
}

/* 操作部 */
.controls {
  background: linear-gradient(#232a62, #171c44);
  border-top: 2px solid rgba(255, 255, 255, 0.22);
}
.palette-canvas {
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px #0a0c1e, 0 6px 14px rgba(0, 0, 0, 0.5);
}
.bar {
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px #0a0c1e, 0 6px 14px rgba(0, 0, 0, 0.5);
}

/* 結果 */
.screen.result {
  position: relative;
  overflow: hidden; /* 回る飾りを画面の幅からはみ出させない */
}
.result-title {
  position: relative;
  margin: 0.3em 0 0.4em;
  font-size: clamp(2rem, 9vw, 2.6rem);
  font-weight: 900;
  animation: title-in 0.55s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
.result-cleared {
  color: #ffe066;
  background: linear-gradient(#fff6b0, #ffd43b 55%, #ff922b);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 #5c3a00);
}
.result-detected {
  filter: drop-shadow(0 3px 0 #4a0d16);
  animation: title-in 0.4s ease-out both, caught-shake 0.5s 0.4s ease-in-out;
}
@keyframes caught-shake {
  20% {
    translate: -6px 0;
  }
  40% {
    translate: 6px 0;
  }
  60% {
    translate: -4px 0;
  }
  80% {
    translate: 3px 0;
  }
}
.result-burst {
  display: none;
}
.result-screen-cleared .result-burst {
  display: block;
  position: absolute;
  left: 50%;
  top: -60px;
  width: 360px;
  height: 360px;
  margin-left: -180px;
  pointer-events: none;
  background: repeating-conic-gradient(rgba(255, 224, 102, 0.16) 0deg 10deg, transparent 10deg 20deg);
  -webkit-mask-image: radial-gradient(closest-side, #000 20%, transparent);
  mask-image: radial-gradient(closest-side, #000 20%, transparent);
  animation: burst-spin 14s linear infinite;
}
@keyframes burst-spin {
  to {
    rotate: 360deg;
  }
}
.screen.result > :not(.result-burst) {
  position: relative;
}
.stat {
  border: 1px solid var(--line);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
  animation: stat-in 0.4s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}
.stat:nth-child(1) {
  animation-delay: 0.15s;
}
.stat:nth-child(2) {
  animation-delay: 0.25s;
}
.stat:nth-child(3) {
  animation-delay: 0.35s;
}
.stat:nth-child(4) {
  animation-delay: 0.45s;
}
@keyframes stat-in {
  from {
    opacity: 0;
    translate: 0 14px;
    scale: 0.92;
  }
}
.stat-value {
  font-size: 1.6rem;
}
.result-best-new {
  padding: 8px 12px;
  border-radius: 12px;
  border: 2px solid #ffd43b;
  color: #ffe066;
  font-weight: 800;
  background: rgba(255, 212, 59, 0.1);
  animation: stat-in 0.4s 0.7s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}
.result-best-new:empty {
  display: none;
}
.result-best-new::before {
  content: '★ ';
}

/* 仮の図形の舞台の警察にも顔をつける */
.dom-police {
  border: 3px solid #1b1b1b;
}
.dom-police::before {
  content: '';
  position: absolute;
  left: 6px;
  right: 2px;
  top: 4px;
  height: 26px;
  border-radius: 14px;
  background: #e8d7b9;
  border: 3px solid #1b1b1b;
}

/* ---------- 横向き・短い画面 ---------- */
@media (orientation: landscape) and (max-height: 560px) {
  /* Keep the sky below the two score lines predictable across system fonts. */
  .hud-left {
    line-height: 1.25;
  }
  .screen.game {
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .screen.practice {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .screen.practice .practice-actions {
    grid-column: 1;
  }
  .screen.practice .controls {
    grid-row: 1 / span 2;
    grid-column: 2;
  }
  .controls {
    height: 100vh;
    height: 100dvh;
    width: min(52vw, 420px);
    border-top: none;
    border-left: 1px solid var(--line);
  }
  .palette {
    width: min(100%, calc(100dvh - 40px));
  }
}

@media (max-height: 720px) and (orientation: portrait) {
  .controls {
    height: min(40dvh, 300px);
    min-height: 220px;
  }
  .palette {
    width: min(100%, calc(min(40dvh, 300px) - 24px - var(--safe-bottom)));
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast,
  .dom-police {
    transition: none;
  }
  /* 動きを減らす設定では、飾りの動きを止める（表示そのものは変えない） */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

.practice-overview {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
}
.practice-overview li + li { margin-top: .6em; }

/* ガイド練習の停止・戻る・完了操作をWebGLキャンバスより手前に置く。 */
.guide-practice-tools {
  position: absolute;
  top: calc(8px + var(--safe-top));
  left: calc(8px + var(--safe-left));
  right: calc(8px + var(--safe-right));
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.guide-practice-tools .btn { width: auto; max-width: 100%; margin: 0; padding: 8px 12px; }
.guide-practice-progress {
  margin: 0;
  font-size: .95rem;
  font-weight: 700;
}
.guide-practice-actions {
  position: absolute;
  inset: 0;
  z-index: 15;
  overflow: auto;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  background: rgba(11, 13, 34, .94);
  display: flex;
  flex-direction: column;
  justify-content: safe center;
  align-items: center;
  gap: 8px;
}
.guide-practice-actions .btn { margin: 0; max-width: 100%; }

.ranking-link {
  display: block;
  text-align: center;
  text-decoration: none;
}
.ranking-result .rank-list {
  --ranking-row-height: 2.75em;
  max-block-size: calc(10 * var(--ranking-row-height));
  overflow-y: auto;
}
.ranking-result .rank-row {
  block-size: var(--ranking-row-height);
  box-sizing: border-box;
  padding-block: 0;
}
.ranking-result .rank-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.dom-hero.dom-hero-cleared {
  background: transparent var(--clear-portrait) center bottom / contain no-repeat !important;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.dom-hero-cleared > *, .dom-hero-cleared::before, .dom-hero-cleared::after { visibility: hidden; }
