:root {
  --ink: #efe6cf;
  --ink-dim: rgba(239, 230, 207, 0.62);
  --ink-faint: rgba(239, 230, 207, 0.38);
  --shade: rgba(8, 7, 4, 0.72);
  --mincho: 'Shippori Mincho', 'Hiragino Mincho ProN', 'Yu Mincho', 'YuMincho', serif;
  --sans: system-ui, -apple-system, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--ink);
  font-family: var(--mincho);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

body.pad,
body.pad #c {
  cursor: none;
}

#c {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  outline: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

/* ---------- 重ね表示 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.6s ease;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- タイトル ---------- */
#title {
  background:
    radial-gradient(ellipse at 50% 46%, rgba(10, 9, 5, 0.25) 0%, rgba(6, 5, 3, 0.78) 72%),
    linear-gradient(rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.42));
  transition: opacity 2.4s ease;
}

.title-inner {
  text-align: center;
  padding: 0 16px;
  transform: translateY(-2vh);
}

#title h1 {
  margin: 0;
  font-weight: 400;
  font-size: clamp(2.1rem, 6.4vw, 4.4rem);
  letter-spacing: 0.18em;
  margin-right: -0.18em;
  line-height: 1.3;
  color: var(--ink);
  text-shadow:
    0 0 28px rgba(255, 236, 170, 0.18),
    0 2px 18px rgba(0, 0, 0, 0.6);
}

#title .sub {
  margin: 0.6em 0 0;
  font-style: italic;
  font-size: clamp(0.85rem, 1.6vw, 1.05rem);
  letter-spacing: 0.12em;
  color: var(--ink-dim);
}

#title .welcome {
  margin: 1.6em 0 0;
  font-size: 0.95rem;
  letter-spacing: 0.2em;
  color: var(--ink-dim);
}

#title .start {
  margin-top: 3.2em;
  padding: 0.7em 1.6em;
  font-size: clamp(0.95rem, 1.8vw, 1.1rem);
  letter-spacing: 0.24em;
  color: var(--ink);
  border-bottom: 1px solid rgba(239, 230, 207, 0.35);
  animation: breathe 3.6s ease-in-out infinite;
}

#title .start:hover,
#title .start:focus-visible {
  border-bottom-color: rgba(239, 230, 207, 0.85);
  outline: none;
}

@keyframes breathe {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

#title .note {
  margin: 2.4em 0 0;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
}

#title .controls {
  margin: 1em 0 0;
  font-family: var(--sans);
  font-size: 0.72rem;
  line-height: 2;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}

/* ---------- 遊んでいる間の表示 ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  transition: opacity 2s ease;
}

#hud.hide {
  opacity: 0;
}

#reticle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 3px;
  margin: -1.5px 0 0 -1.5px;
  border-radius: 50%;
  background: rgba(255, 250, 235, 0.45);
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.6);
}

#prompt {
  position: absolute;
  left: 50%;
  top: calc(50% + 46px);
  transform: translate(-50%, 6px);
  display: flex;
  align-items: center;
  gap: 0.6em;
  font-size: 0.95rem;
  letter-spacing: 0.22em;
  color: var(--ink);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.85);
  opacity: 0;
  transition:
    opacity 0.5s ease,
    transform 0.5s ease;
}

#prompt.show {
  opacity: 0.92;
  transform: translate(-50%, 0);
}

#prompt.show.dim {
  opacity: 0.4;
}

#prompt .key {
  display: inline-grid;
  place-items: center;
  min-width: 1.7em;
  height: 1.7em;
  padding: 0 0.3em;
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0;
  border: 1px solid rgba(239, 230, 207, 0.55);
  border-radius: 3px;
}

body.touch #prompt {
  display: none;
}

/* ゲームパッドのボタンの絵 */
.g {
  display: inline-block;
  height: 1.55em;
  width: auto;
  vertical-align: -0.42em;
  overflow: visible;
}

#title .controls .g,
#pause .resume .g,
#hint .g {
  height: 2.1em;
  vertical-align: -0.62em;
}

#title .controls .g {
  margin: 0 0.15em;
}

#prompt .key.glyph {
  border: none;
  min-width: 0;
  height: auto;
  padding: 0;
  font-size: 0.95rem;
}

#caption {
  position: absolute;
  left: 50%;
  bottom: 15%;
  transform: translateX(-50%);
  width: min(92vw, 40em);
  text-align: center;
  font-size: clamp(0.95rem, 2vw, 1.15rem);
  letter-spacing: 0.2em;
  color: var(--ink);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.9);
  opacity: 0;
  transition: opacity 2.2s ease;
}

#caption.show {
  opacity: 0.9;
}

#hint {
  position: absolute;
  left: 50%;
  bottom: 6%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  opacity: 0;
  transition: opacity 1.6s ease;
}

#hint.show {
  opacity: 1;
}

/* ---------- 一時停止 ---------- */
#pause {
  background: rgba(6, 5, 3, 0.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition: opacity 0.35s ease;
  cursor: pointer;
}

#pause .panel {
  text-align: center;
  padding: 16px;
  width: min(100%, 380px);
  max-height: 100%;
  overflow-y: auto;
}

#pause h2 {
  margin: 0;
  font-weight: 400;
  font-size: 1.6rem;
  letter-spacing: 0.3em;
  margin-right: -0.3em;
}

#pause .resume {
  margin: 0.8em 0 2.4em;
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  color: var(--ink-dim);
  animation: breathe 3.6s ease-in-out infinite;
}

.panel-controls {
  display: grid;
  gap: 1.1em;
  cursor: default;
  font-family: var(--sans);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
}

.panel-controls label {
  display: grid;
  grid-template-columns: 7.5em 1fr;
  align-items: center;
  gap: 1em;
  text-align: left;
}

.panel-controls label.check {
  grid-template-columns: auto 1fr;
  gap: 0.7em;
}

.panel-controls input[type='range'] {
  width: 100%;
  accent-color: #c9b25c;
}

.panel-controls input[type='checkbox'] {
  accent-color: #c9b25c;
  width: 1rem;
  height: 1rem;
}

/* ボタン表示の切り替え（自動／type1／type2） */
.seg {
  display: grid;
  grid-template-columns: 7.5em 1fr;
  align-items: center;
  gap: 1em;
  text-align: left;
}

.seg-opts {
  display: flex;
  border: 1px solid rgba(239, 230, 207, 0.28);
  border-radius: 2px;
  overflow: hidden;
}

.seg-opts button {
  flex: 1;
  padding: 0.45em 0.2em;
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  transition:
    background 0.2s ease,
    color 0.2s ease;
}

.seg-opts button + button {
  border-left: 1px solid rgba(239, 230, 207, 0.18);
}

.seg-opts button.on {
  background: rgba(201, 178, 92, 0.28);
  color: var(--ink);
}

/* ゲームパッドで選んでいる項目 */
body.pad .nav-focus {
  outline: 1px solid rgba(239, 230, 207, 0.7);
  outline-offset: 5px;
  border-radius: 2px;
}

body.pad #title .start.nav-focus {
  outline: none;
  border-bottom-color: rgba(239, 230, 207, 0.9);
}

button.ghost {
  justify-self: center;
  margin-top: 0.6em;
  padding: 0.55em 1.4em;
  font-family: var(--mincho);
  font-size: 0.9rem;
  letter-spacing: 0.2em;
  color: var(--ink);
  border: 1px solid rgba(239, 230, 207, 0.3);
  border-radius: 2px;
  transition:
    border-color 0.3s ease,
    background 0.3s ease;
}

button.ghost:hover,
button.ghost:focus-visible {
  border-color: rgba(239, 230, 207, 0.75);
  background: rgba(239, 230, 207, 0.06);
  outline: none;
}

/* ---------- おしまい ---------- */
#ending {
  align-items: flex-end;
  padding-bottom: 9vh;
  background: linear-gradient(transparent 55%, rgba(0, 0, 0, 0.55));
  transition: opacity 5s ease;
}

.ending-inner {
  text-align: center;
  padding: 0 16px;
}

.e-title {
  margin: 0;
  font-size: clamp(1.7rem, 4.6vw, 3rem);
  letter-spacing: 0.2em;
  margin-right: -0.2em;
  text-shadow: 0 0 24px rgba(255, 236, 170, 0.14);
}

.e-sub {
  margin: 0.9em 0 0;
  font-size: 0.95rem;
  letter-spacing: 0.4em;
  margin-right: -0.4em;
  color: var(--ink-dim);
}

.e-credit {
  margin: 2.2em 0 0;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
}

.e-buttons {
  display: flex;
  justify-content: center;
  gap: 1.2em;
  margin-top: 2.2em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 2s ease;
}

#ending.buttons .e-buttons {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- 音が出せないときの案内 ---------- */
#audio-notice {
  position: fixed;
  left: 50%;
  top: max(16px, env(safe-area-inset-top));
  transform: translateX(-50%);
  padding: 0.5em 1.2em;
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  color: var(--ink);
  background: rgba(10, 9, 6, 0.55);
  border: 1px solid rgba(239, 230, 207, 0.25);
  border-radius: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
}

#audio-notice.show {
  opacity: 1;
}

/* ---------- 読み込み中 ---------- */
#loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.2s ease;
}

#loading.show {
  opacity: 1;
  pointer-events: auto;
}

#loading p {
  font-size: 0.85rem;
  letter-spacing: 0.3em;
  color: var(--ink-faint);
  animation: breathe 2.4s ease-in-out infinite;
}

/* ---------- タッチ操作 ---------- */
#touch {
  position: fixed;
  inset: 0;
}

#touch[hidden] {
  display: none;
}

#joy {
  position: absolute;
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border-radius: 50%;
  border: 1px solid rgba(239, 230, 207, 0.25);
  background: rgba(239, 230, 207, 0.04);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

#joy.on {
  opacity: 1;
}

#knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(239, 230, 207, 0.22);
  transform: translate(-50%, -50%);
}

#act {
  position: absolute;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(26px, env(safe-area-inset-bottom));
  min-width: 92px;
  height: 52px;
  padding: 0 1.2em;
  border-radius: 26px;
  border: 1px solid rgba(239, 230, 207, 0.5);
  background: rgba(10, 9, 6, 0.35);
  font-size: 1rem;
  letter-spacing: 0.2em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

#act.show {
  opacity: 1;
  pointer-events: auto;
}

#pauseBtn {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  top: max(12px, env(safe-area-inset-top));
  width: 40px;
  height: 40px;
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-dim);
}

#debug {
  position: fixed;
  left: 8px;
  top: 6px;
  font: 11px/1.4 ui-monospace, Menlo, monospace;
  color: #9f9;
  text-shadow: 0 0 3px #000;
  pointer-events: none;
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
}

@media (prefers-reduced-motion: reduce) {
  #title .start,
  #pause .resume,
  #loading p {
    animation: none;
    opacity: 1;
  }
}
