/* ===== BOX TIMER ===== */
:root {
  --c: #f2f5ff;              /* 表示色（JSで切り替え） */
  --rgb: 242, 245, 255;      /* 表示色のRGB（グロー用） */
  --ghost: 0.06;             /* 消灯セグメントの濃さ */
  --ar: 2.4746;              /* 時計表示の縦横比（app.js の viewBox と同じ） */
  --panel: #0c0c0f;
  --line: #1e1e24;
  --field: #16161b;
  --field-line: #2a2a32;
  --text: #ececf1;
  --muted: #8b8b96;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: #000; }
body {
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
button, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
svg { display: block; }

/* ===== レイアウト（縦表示が基本） ===== */
.app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: calc(var(--sat) + 14px) calc(var(--sar) + 12px) calc(var(--sab) + 6px) calc(var(--sal) + 12px);
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  container-type: size;
}

.status {
  height: 18px;
  display: flex;
  align-items: center;
  gap: 1em;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.28em;
  white-space: nowrap;
  color: rgba(var(--rgb), 0.8);
  font-variant-numeric: tabular-nums;
}
.status-sub { color: rgba(var(--rgb), 0.5); }
.state-paused .status-sub { animation: blink 1.2s step-end infinite; }
@keyframes blink { 50% { opacity: 0.15; } }

/* 外枠（表示色と同じ色） */
.frame {
  width: min(100%, 1000px);
  width: min(100cqw, (100cqh - 32px) * var(--ar), 1000px);
  border: clamp(2px, 0.35vmin + 1px, 4px) solid var(--c);
  border-radius: clamp(10px, 2.2vmin, 22px);
  background: #000;
  box-shadow:
    0 0 10px rgba(var(--rgb), 0.4),
    0 0 26px rgba(var(--rgb), 0.15),
    inset 0 0 14px rgba(var(--rgb), 0.1);
  transition: border-color 0.2s, box-shadow 0.2s;
}

/* 7セグ時計 */
.clock {
  width: 100%;
  height: auto;
  aspect-ratio: 633.5 / 256;
  overflow: visible;
  filter: drop-shadow(0 0 3px rgba(var(--rgb), 0.55));
}
.seg { fill: var(--c); opacity: var(--ghost); }
.seg.on { opacity: 1; }

/* ===== 設定パネル ===== */
.panel {
  flex: none;
  width: 100%;
  max-width: 620px;
  max-height: 66%;
  margin: 0 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
}
.panel-head { display: none; }

.controls { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
.btn {
  height: 56px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.1em;
  transition: transform 0.08s, background-color 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-main {
  color: var(--c);
  border: 1.5px solid var(--c);
  background: rgba(var(--rgb), 0.1);
  box-shadow: 0 0 12px rgba(var(--rgb), 0.22);
}
.state-running .btn-main { background: rgba(var(--rgb), 0.2); }
.btn-sub { color: var(--text); border: 1px solid var(--field-line); background: var(--field); }
.btn-small { height: 44px; font-size: 15px; width: 100%; margin-top: 4px; }

.group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.label { font-size: 14px; font-weight: 600; color: var(--muted); letter-spacing: 0.04em; }
.hint { display: none; font-size: 12px; color: var(--muted); }
.state-running .hint, .state-paused .hint { display: block; }

.time-pick { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.select {
  -webkit-appearance: none;
  appearance: none;
  min-width: 66px;
  padding: 8px 28px 8px 12px;
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--field) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238b8b96' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 10px center / 10px 6px;
  border: 1px solid var(--field-line);
  border-radius: 10px;
}
.select:disabled { opacity: 0.4; }

.swatches { display: flex; justify-content: space-between; gap: 6px; padding: 4px 2px; }
.swatch {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 50%;
  background: var(--sw);
  box-shadow: 0 0 8px rgba(var(--sw-rgb), 0.6);
  outline: 2px solid transparent;
  outline-offset: 3px;
  transition: outline-color 0.15s, transform 0.1s;
}
.swatch:active { transform: scale(0.92); }
.swatch[aria-pressed="true"] { outline-color: var(--sw); }

.more summary { list-style: none; display: flex; align-items: center; justify-content: space-between; min-height: 32px; cursor: pointer; }
.more summary::-webkit-details-marker { display: none; }
.more summary::after {
  content: "";
  width: 8px; height: 8px;
  margin-right: 4px;
  border-right: 1.6px solid var(--muted);
  border-bottom: 1.6px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.2s;
}
.more[open] summary::after { transform: rotate(-135deg) translateY(-2px); }
.buzz-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.buzz-row { display: grid; grid-template-columns: 1fr auto 44px; align-items: center; gap: 8px; }
.buzz-row .label { font-weight: 500; color: var(--text); font-size: 14px; }
.buzz-row .select { font-size: 15px; min-width: 0; }

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--field-line);
  background: var(--field);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.preview svg { fill: var(--text); stroke: none; }

.credit {
  flex: none;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.28);
}

.ls-btn, .scrim { display: none; }
.noscript { position: fixed; inset: auto 0 40% 0; text-align: center; color: #aaa; }

/* ===== 横表示：タイマーを見る用途 ===== */
@media (orientation: landscape) {
  .app {
    gap: 0;
    padding: calc(var(--sat) + 10px) calc(var(--sar) + 14px) calc(var(--sab) + 10px) calc(var(--sal) + 14px);
  }
  .stage { padding-bottom: 60px; }
  .frame { width: min(100cqw, (100cqh - 32px) * var(--ar), 1600px); }

  .ls-btn { display: grid; place-items: center; position: absolute; z-index: 5; }
  .ls-btn svg { width: 24px; height: 24px; }

  /* スタート/ストップ：目立たないが押しやすい大きさ */
  .ls-toggle {
    right: calc(var(--sar) + 16px);
    bottom: calc(var(--sab) + 10px);
    width: 64px; height: 64px;
    border-radius: 50%;
    border: 1.5px solid rgba(var(--rgb), 0.25);
    background: rgba(var(--rgb), 0.03);
    transition: background-color 0.15s, border-color 0.15s;
  }
  .ls-toggle::after { content: ""; position: absolute; inset: -12px; border-radius: 50%; }
  .ls-toggle:active { background: rgba(var(--rgb), 0.15); border-color: rgba(var(--rgb), 0.6); }
  .ls-toggle svg { width: 26px; height: 26px; fill: rgba(var(--rgb), 0.45); }
  .ls-toggle .ic-pause, .state-running .ls-toggle .ic-play { display: none; }
  .state-running .ls-toggle .ic-pause { display: block; }

  .ls-menu {
    top: calc(var(--sat) + 8px);
    right: calc(var(--sar) + 14px);
    width: 48px; height: 48px;
    border-radius: 14px;
  }
  .ls-menu::after { content: ""; position: absolute; inset: -8px; }
  .ls-menu svg { fill: none; stroke: rgba(255, 255, 255, 0.4); stroke-width: 2; stroke-linecap: round; }
  .ls-menu:active { background: rgba(255, 255, 255, 0.08); }

  .credit {
    position: absolute;
    left: calc(var(--sal) + 16px);
    bottom: calc(var(--sab) + 12px);
    text-align: left;
  }

  /* 設定はメニュー（右からスライド） */
  .panel {
    position: fixed;
    z-index: 20;
    top: 0; right: 0; bottom: 0;
    width: min(380px, 88vw);
    max-width: none;
    max-height: none;
    margin: 0;
    padding: calc(var(--sat) + 12px) calc(var(--sar) + 16px) calc(var(--sab) + 16px) 16px;
    border-radius: 20px 0 0 20px;
    border-right: 0;
    transform: translateX(105%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0s linear 0.25s;
  }
  .menu-open .panel { transform: none; visibility: visible; transition: transform 0.25s ease; }
  .panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.1em;
  }
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 15;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }
  .menu-open .scrim { opacity: 1; pointer-events: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .scrim { transition: none !important; }
}
