* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* テーマごとにJSから書き換える */
  --bg: #eaebed;
  --text: rgba(115, 120, 130, 0.6);
  --ui-bg: rgba(255, 255, 255, 0.62);
  --ui-border: rgba(125, 130, 140, 0.18);
  --ui-text: rgba(95, 100, 110, 0.85);
  --ui-active: rgba(255, 255, 255, 0.95);
  --gear-bg: rgba(52, 56, 64, 0.78);
  --gear-text: rgba(255, 255, 255, 0.92);
  --accent: #93aec2;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, "Hiragino Maru Gothic ProN", "Hiragino Sans", sans-serif;
}

body { background: var(--bg); transition: background 1.2s ease; }
/* 最終保険：万一キャンバスが描けなくても月面だけは見えるように */
body[data-theme="tsuki"] {
  background: var(--bg) url("assets/moon-surface-bg.jpeg") center / cover no-repeat;
}

canvas { position: fixed; inset: 0; display: block; }

#hint {
  position: fixed; left: 0; right: 0; bottom: 18%;
  text-align: center;
  color: var(--text);
  font-size: 16px;
  letter-spacing: 0.25em;
  pointer-events: none;
  transition: opacity 3s ease, color 1.2s ease;
}
#hint.hide { opacity: 0; }

/* 右上の設定ボタン（濃い丸） */
#gear {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  right: 16px;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--gear-bg);
  color: var(--gear-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  transition: background 1.2s, color 1.2s, opacity 0.5s;
}
#gear.hidden-ui { opacity: 0; pointer-events: none; }

/* 下部のモード切替（アイコンのピル） */
#modes {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 6px;
  border-radius: 999px;
  border: 1px solid var(--ui-border);
  background: var(--ui-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.04);
  z-index: 20;
  transition: opacity 0.5s, background 1.2s;
}
#modes.hidden-ui { opacity: 0; pointer-events: none; }
.mode {
  width: 44px; height: 44px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ui-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.3s, background 0.3s, box-shadow 0.3s;
}
.mode svg { width: 21px; height: 21px; }
.mode.active {
  opacity: 1;
  background: var(--ui-active);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ねむるモードのタイマー円 */
#sleepCircle {
  position: fixed;
  left: 50%; top: 44%;
  transform: translate(-50%, -50%);
  width: 158px; height: 158px;
  border-radius: 50%;
  border: 1px solid var(--ui-border);
  background: var(--ui-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--ui-text);
  cursor: pointer;
  z-index: 16;
  opacity: 0.9;
  transition: opacity 0.6s;
}
#sleepCircle.hidden { opacity: 0; pointer-events: none; }
#sleepCircle .moon { font-size: 14px; opacity: 0.7; }
#sleepTime {
  font-size: 30px;
  font-weight: 300;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}
#sleepNote { font-size: 9px; letter-spacing: 0.15em; opacity: 0.6; }

/* 設定パネル（設計図のリスト形式） */
#panel {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 64px);
  right: 16px;
  width: min(320px, calc(100vw - 32px));
  max-height: calc(100vh - 150px);
  overflow-y: auto;
  padding: 18px 18px 10px;
  border-radius: 20px;
  border: 1px solid var(--ui-border);
  background: var(--ui-active);
  color: var(--ui-text);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.12);
  z-index: 30;
  transition: opacity 0.3s, transform 0.3s;
}
#panel.hidden {
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}
.panel-title {
  font-size: 12px;
  letter-spacing: 0.35em;
  margin-bottom: 14px;
  opacity: 0.65;
}
#panel .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  font-size: 12.5px;
  letter-spacing: 0.1em;
  border-bottom: 1px solid rgba(125, 130, 140, 0.1);
}
#panel .row:last-of-type { border-bottom: none; }
.lbl {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.lbl svg { width: 16px; height: 16px; opacity: 0.65; }
.slider-row input[type="range"] {
  flex: 1;
  max-width: 150px;
  height: 4px;
  accent-color: var(--accent);
}
.value-row { cursor: pointer; }
.value-row .val { opacity: 0.75; white-space: nowrap; }
.value-row .val::after { content: " ›"; opacity: 0.5; }
.value-row:active { opacity: 0.6; }

/* iOS風スイッチ */
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input {
  position: absolute; inset: 0;
  opacity: 0; margin: 0;
  cursor: pointer;
  z-index: 1;
}
.switch i {
  display: block;
  width: 42px; height: 24px;
  border-radius: 12px;
  background: rgba(125, 130, 140, 0.3);
  transition: background 0.25s;
  position: relative;
}
.switch i::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.25s;
}
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }

#panelClose {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ui-text);
  font-size: 12px;
  letter-spacing: 0.3em;
  padding: 12px 8px 8px;
  cursor: pointer;
  opacity: 0.7;
}

/* ねむるモードの終わりに、ゆっくり暗くなる */
#sleepOverlay {
  position: fixed; inset: 0;
  background: #04050a;
  opacity: 0;
  pointer-events: none;
  transition: opacity 3s ease;
  z-index: 15;
}
