/* timer.css — タイマー & ストップウォッチ (Tailwind不使用) */

/* ===== 変数 ===== */
:root {
  --blue:      #3b82f6;
  --blue-dk:   #2563eb;
  --blue-sh:   rgba(59,130,246,0.25);
  --red:       #ef4444;
  --red-dk:    #dc2626;
  --red-sh:    rgba(239,68,68,0.25);
  --gray:      #94a3b8;
  --indigo:    #6366f1;
  --indigo-dk: #4f46e5;
  --text:      #1e293b;
  --text-sub:  #64748b;
  --text-dim:  #94a3b8;
  --bg:        #f8fafc;
  --surface:   #ffffff;
  --surface2:  #f1f5f9;
  --border:    #e2e8f0;
  --font: "Noto Sans JP","Hiragino Kaku Gothic ProN","Hiragino Sans",Meiryo,sans-serif;
  --ctrl-h: 80px;
  --tab-w:  80px;
  --radius: 12px;
}
html[data-theme="dark"] {
  --text:     #e2e8f0;
  --text-sub: #94a3b8;
  --text-dim: #475569;
  --bg:       #0f172a;
  --surface:  #1e293b;
  --surface2: #0f172a;
  --border:   #334155;
}

/* ===== リセット ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  touch-action: manipulation;
  transition: background 0.3s;
}

.hidden { display: none !important; }

/* ===== レイアウト ===== */
#main-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

#tab-nav {
  display: flex;
  flex-direction: row;
  height: 64px;
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

@media (min-width: 640px) {
  body       { flex-direction: row; }
  #main-area { height: 100%; }
  #tab-nav   { flex-direction: column; width: var(--tab-w); height: auto; border-top: none; border-left: 1px solid var(--border); }
  :root      { --ctrl-h: 120px; }
}

/* ===== ビュー ===== */
#view-timer,
#view-stopwatch {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  height: 100%;
  overflow: hidden;
}

/* ===== 上部コントロール (Timer) ===== */
#top-controls {
  position: absolute;
  top: 1rem; left: 1rem;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#back-btn, #fs-btn {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.65);
  border: none; cursor: pointer;
  color: var(--text-sub);
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
}
#back-btn:hover, #fs-btn:hover { background: rgba(255,255,255,0.95); color: var(--text); }
#back-btn svg, #fs-btn svg { width: 22px; height: 22px; }

html[data-theme="dark"] #back-btn,
html[data-theme="dark"] #fs-btn       { background: rgba(0,0,0,0.35); }
html[data-theme="dark"] #back-btn:hover,
html[data-theme="dark"] #fs-btn:hover  { background: rgba(0,0,0,0.6); }

/* ===== フルスクリーン解除ボタン ===== */
#fs-exit-overlay {
  display: none;
  position: absolute; top: 1rem; right: 1rem; z-index: 50;
}
#fs-exit-btn {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: none; cursor: pointer;
  color: var(--text-sub);
  transition: background 0.2s;
}
#fs-exit-btn:hover { background: rgba(255,255,255,0.35); }
#fs-exit-btn svg { width: 24px; height: 24px; }

/* ===== プログレスバー ===== */
#progress-container {
  position: absolute; top: 0; left: 0; right: 0;
  height: 6px; background: var(--border); z-index: 10;
}
#progress-bar {
  height: 100%; width: 100%;
  background: var(--blue);
  transition: width 0.1s linear, background 0.3s;
}
#progress-bar.warning { background: var(--red); }

/* ===== タイマー中央表示 ===== */
#timer-center {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 0 1rem;
}

#timer-status {
  font-size: clamp(0.7rem, 2vw, 1.1rem);
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

#timer-display {
  display: flex; align-items: baseline;
  font-size: clamp(3rem, 18vw, 14rem);
  font-weight: 700; line-height: 1;
  letter-spacing: -0.02em;
  color: var(--text);
  user-select: none;
  font-variant-numeric: tabular-nums;
}
#timer-display .sep    { color: var(--border); margin: 0 0.04em; }
#minus-sign            { color: var(--red); margin-right: 0.04em; }
#timer-display.overtime { color: var(--red); }

/* ===== ストップヒント ===== */
#stop-hint {
  position: absolute; top: 4.5rem; right: 1rem;
  background: var(--surface);
  border: 1px solid #fecdd3;
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  max-width: min(85vw, 280px);
  z-index: 30;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  cursor: pointer;
  animation: fadeDown 0.35s ease;
}
#stop-hint h4 { font-size: 0.82rem; font-weight: 700; margin-bottom: 0.2rem; }
#stop-hint p  { font-size: 0.73rem; color: var(--text-sub); line-height: 1.5; }
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== 下部コントロール ===== */
#bottom-controls {
  height: var(--ctrl-h);
  display: flex; align-items: center; justify-content: center;
  gap: 2rem; padding: 0 1.5rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0; position: relative;
}

#stop-tooltip {
  position: absolute; top: -2.5rem; left: 50%;
  transform: translateX(-50%);
  background: var(--red); color: #fff;
  font-size: 0.72rem; font-weight: 700;
  padding: 0.35rem 0.8rem; border-radius: 999px;
  white-space: nowrap; pointer-events: none;
  animation: bounce 1s infinite;
}
@keyframes bounce {
  0%,100% { transform: translateX(-50%) translateY(0); }
  50%      { transform: translateX(-50%) translateY(-5px); }
}

/* ctrl ボタン (設定, リセット) */
.ctrl-btn {
  display: flex; flex-direction: column;
  align-items: center; gap: 0.25rem;
  background: none; border: none; cursor: pointer;
  color: var(--text-sub); padding: 0.5rem;
  border-radius: 8px;
  font-size: 0.68rem; font-weight: 700; font-family: var(--font);
  transition: color 0.2s, background 0.2s;
}
.ctrl-btn:hover { background: var(--surface2); color: var(--text); }
.ctrl-btn svg { width: 26px; height: 26px; }

/* メインボタン */
.btn-main {
  width: 56px; height: 56px;
  border-radius: 50%; border: none; cursor: pointer;
  background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px var(--blue-sh);
  transition: background 0.2s, transform 0.05s, box-shadow 0.2s;
}
.btn-main:hover  { background: var(--blue-dk); }
.btn-main:active { transform: scale(0.95); }
.btn-main svg    { width: 24px; height: 24px; }

.btn-main.btn-alarm { background: var(--red); box-shadow: 0 4px 12px var(--red-sh); }
.btn-main.btn-alarm:hover { background: var(--red-dk); }
.btn-main.btn-ended { background: var(--gray); box-shadow: none; }
.btn-main.btn-guide { animation: pulse-guide 2s infinite; }
@keyframes pulse-guide {
  0%   { box-shadow: 0 0 0 0 rgba(239,68,68,0.7); }
  70%  { box-shadow: 0 0 0 12px rgba(239,68,68,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}

@media (min-width: 640px) {
  .btn-main { width: 72px; height: 72px; }
  .btn-main svg { width: 30px; height: 30px; }
  .ctrl-btn svg { width: 30px; height: 30px; }
  .ctrl-btn { font-size: 0.75rem; }
}

/* ===== パネル共通 ===== */
.panel {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  z-index: 30;
  opacity: 0; visibility: hidden;
  transition: transform 0.28s ease, opacity 0.28s ease, visibility 0.28s;
}
.panel.panel-open { opacity: 1; visibility: visible; }

#settings-panel {
  bottom: var(--ctrl-h); left: 0.5rem; right: 0.5rem;
  max-height: 65vh; overflow-y: auto;
  padding: 1.25rem;
  border-radius: 16px;
  transform: translateY(110%);
  max-width: 580px; margin: auto;
}
#settings-panel.panel-open { transform: translateY(0); }

#global-settings-modal {
  bottom: calc(var(--ctrl-h) + 0.5rem); right: 1rem;
  width: 260px; padding: 1.1rem;
  border-radius: 12px;
  transform: translateY(8px);
}
#global-settings-modal.panel-open { transform: translateY(0); }

.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.panel-header h3 { font-size: 0.95rem; font-weight: 700; }
.panel-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-sub); padding: 0.2rem;
  border-radius: 4px; display: flex;
  transition: color 0.2s;
}
.panel-close:hover { color: var(--text); }
.panel-close svg { width: 18px; height: 18px; }

#panel-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.2); z-index: 20;
}

/* ===== 時間入力 ===== */
.time-inputs {
  display: flex; align-items: center; justify-content: center;
  gap: 0.25rem;
  background: var(--surface2);
  padding: 0.75rem 1rem; border-radius: 12px;
  margin-bottom: 1rem;
}
.time-input-group { flex: 1; text-align: center; }
.time-input-group input {
  width: 100%;
  font-size: clamp(1.5rem, 5vw, 2.1rem);
  font-weight: 700; color: var(--text);
  background: none; border: none; outline: none;
  text-align: center;
  font-variant-numeric: tabular-nums; font-family: var(--font);
}
.time-input-group input:focus { color: var(--blue); }
.time-input-group input::-webkit-inner-spin-button,
.time-input-group input::-webkit-outer-spin-button { -webkit-appearance: none; }
.time-input-group input[type="number"] { -moz-appearance: textfield; }
.time-input-label { font-size: 0.68rem; font-weight: 700; color: var(--text-sub); margin-top: 0.2rem; }
.time-sep { font-size: 1.4rem; color: var(--border); font-weight: 700; padding-bottom: 1.5rem; }

/* 増減ボタン */
.adj-buttons {
  display: grid; grid-template-columns: repeat(4,1fr);
  gap: 0.4rem; margin-bottom: 1rem;
}
.adj-btn {
  padding: 0.45rem 0;
  border: none; border-radius: 7px;
  font-size: 0.82rem; font-weight: 700; cursor: pointer;
  font-family: var(--font); transition: background 0.15s;
}
.adj-btn.minus { background: #fef2f2; color: var(--red); }
.adj-btn.minus:hover { background: #fee2e2; }
.adj-btn.plus  { background: #eff6ff; color: var(--blue); }
.adj-btn.plus:hover  { background: #dbeafe; }
html[data-theme="dark"] .adj-btn.minus { background: rgba(239,68,68,0.12); }
html[data-theme="dark"] .adj-btn.minus:hover { background: rgba(239,68,68,0.22); }
html[data-theme="dark"] .adj-btn.plus  { background: rgba(59,130,246,0.12); }
html[data-theme="dark"] .adj-btn.plus:hover  { background: rgba(59,130,246,0.22); }

/* プリセット */
.preset-grid {
  display: grid; grid-template-columns: repeat(4,1fr);
  gap: 0.4rem; padding-top: 0.9rem;
  border-top: 1px solid var(--border);
}
.preset-btn {
  padding: 0.55rem; background: var(--surface);
  border: 2px solid var(--border); border-radius: 9px;
  font-size: 0.82rem; font-weight: 700; color: var(--text);
  cursor: pointer; font-family: var(--font);
  transition: border-color 0.15s, color 0.15s;
}
.preset-btn:hover { border-color: var(--blue); color: var(--blue); }

/* ===== グローバル設定トグル ===== */
.setting-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.55rem 0;
}
.setting-row + .setting-row { border-top: 1px solid var(--border); }
.setting-label { font-size: 0.82rem; font-weight: 500; }

.toggle-wrap {
  position: relative; display: inline-block;
  width: 44px; height: 24px; cursor: pointer; flex-shrink: 0;
}
.toggle-wrap input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute; inset: 0;
  background: var(--border); border-radius: 999px;
  transition: background 0.2s;
}
.toggle-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px;
  background: #fff; border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s; pointer-events: none;
}
.toggle-wrap input:checked ~ .toggle-track { background: var(--blue); }
.toggle-wrap input:checked ~ .toggle-thumb { transform: translateX(20px); }

/* ===== フローティング設定ボタン ===== */
#floating-settings-btn {
  position: absolute;
  bottom: calc(var(--ctrl-h) + 0.5rem); right: 1rem;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border);
  cursor: pointer; color: var(--text-sub);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, color 0.2s; z-index: 40;
}
#floating-settings-btn:hover { background: var(--border); color: var(--text); }
#floating-settings-btn svg { width: 19px; height: 19px; }

/* ===== タブ ===== */
.tab-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0.2rem; background: none; border: none; cursor: pointer;
  font-size: 0.63rem; font-weight: 700;
  color: var(--text-sub); font-family: var(--font);
  transition: color 0.2s, background 0.2s;
  border-top: 3px solid transparent;
  padding: 0.5rem;
}
.tab-btn:hover { background: var(--surface2); }
.tab-btn svg { width: 22px; height: 22px; }
.tab-btn.tab-active { color: var(--blue); border-top-color: var(--blue); }

@media (min-width: 640px) {
  .tab-btn { border-top: none; border-right: 3px solid transparent; font-size: 0.72rem; padding: 1.5rem 0; gap: 0.4rem; }
  .tab-btn svg { width: 26px; height: 26px; }
  .tab-btn.tab-active { border-right-color: var(--blue); }
}

/* ===== ストップウォッチ View ===== */
#view-stopwatch { background: var(--bg); }

#sw-display-area {
  flex-shrink: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 3.5rem 1rem 1.5rem;
}
#sw-label {
  font-size: 0.85rem; font-weight: 700;
  color: var(--text-dim); letter-spacing: 0.12em;
  text-transform: uppercase; margin-bottom: 0.4rem;
}
#sw-display {
  display: flex; align-items: baseline;
  font-size: clamp(2.5rem, 13vw, 9rem);
  font-weight: 700; line-height: 1; color: var(--text);
  user-select: none; font-variant-numeric: tabular-nums;
}
#sw-display .sep   { color: var(--border); margin: 0 0.04em; }
#sw-ms-wrap { font-size: 0.42em; color: var(--text-sub); margin-left: 0.1em; }

#laps-container {
  flex: 1; overflow-y: auto;
  padding: 0 1.25rem 0.5rem;
  max-width: 500px; width: 100%; margin: 0 auto;
}
.lap-item {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface2); border-radius: 8px;
  padding: 0.45rem 0.9rem; margin-bottom: 0.4rem;
  font-size: 0.85rem; font-variant-numeric: tabular-nums;
  color: var(--text-sub);
}
.lap-item strong { color: var(--text); font-weight: 700; }

#sw-controls {
  height: var(--ctrl-h); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  gap: 2.5rem;
  background: var(--surface); border-top: 1px solid var(--border);
}
#sw-toggle-btn {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--indigo); border: none; cursor: pointer;
  color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(99,102,241,0.3);
  transition: background 0.2s, transform 0.05s;
}
#sw-toggle-btn:hover  { background: var(--indigo-dk); }
#sw-toggle-btn:active { transform: scale(0.95); }
#sw-toggle-btn svg { width: 26px; height: 26px; }

#sw-lap-reset {
  display: flex; flex-direction: column;
  align-items: center; gap: 0.2rem;
  background: none; border: none; cursor: pointer;
  color: var(--text-sub); font-family: var(--font);
  width: 70px; transition: color 0.2s;
}
#sw-lap-reset:hover { color: var(--text); }
.lap-icon {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
#sw-lap-reset:hover .lap-icon { background: var(--border); }
.lap-icon svg { width: 20px; height: 20px; }
#sw-btn-sub-label { font-size: 0.68rem; font-weight: 700; }
.sw-spacer { width: 70px; }

@media (min-width: 640px) {
  #sw-toggle-btn { width: 72px; height: 72px; }
  #sw-toggle-btn svg { width: 30px; height: 30px; }
}

/* ===== 状態クラス ===== */
body.is-alarm   { animation: alarm-flash 1s infinite; }
@keyframes alarm-flash {
  0%,100% { background-color: #fff1f2; }
  50%     { background-color: #ffe4e6; }
}
html[data-theme="dark"] body.is-alarm { animation: alarm-flash-dk 1s infinite; }
@keyframes alarm-flash-dk {
  0%,100% { background-color: #4c0519; }
  50%     { background-color: #881337; }
}
body.is-warning:not(.is-alarm) { background: #fff8f8; }
html[data-theme="dark"] body.is-warning:not(.is-alarm) { background: #1f0a0d; }

/* ===== フルスクリーン ===== */
body.is-fullscreen #top-controls          { display: none; }
body.is-fullscreen #fs-exit-overlay       { display: block; }
body.is-fullscreen #bottom-controls       { display: none; }
body.is-fullscreen #floating-settings-btn { display: none; }
body.is-fullscreen #timer-status          { display: none; }
body.is-fullscreen #stop-hint             { display: none !important; }
body.is-fullscreen #stop-tooltip          { display: none !important; }
body.is-fullscreen #tab-nav               { display: none; }
body.is-fullscreen #progress-container    { height: 8px; }
body.is-fullscreen #timer-center          { justify-content: center; }

/* ===== ダークモード追加カバレッジ ===== */
html[data-theme="dark"] #bottom-controls {
  background: #1e293b;
  border-color: #334155;
}
html[data-theme="dark"] #tab-nav {
  background: #1e293b;
  border-color: #334155;
}
html[data-theme="dark"] .panel {
  background: #1e293b;
  border-color: #334155;
}
html[data-theme="dark"] .time-inputs {
  background: #0f172a;
}
html[data-theme="dark"] #stop-hint {
  background: #1e293b;
  border-color: #4c0519;
}
html[data-theme="dark"] #sw-controls {
  background: #1e293b;
  border-color: #334155;
}
html[data-theme="dark"] .lap-item {
  background: #0f172a;
}
html[data-theme="dark"] .lap-icon {
  background: #0f172a;
}
html[data-theme="dark"] #sw-lap-reset:hover .lap-icon {
  background: #334155;
}

/* ===== ライトモード: グラデーション背景を無効化 ===== */
html:not([data-theme="dark"]) body::before {
  display: none;
}

/* ===== 軽量モード ===== */
html[data-performance="low"] * { transition: none !important; animation: none !important; }
html[data-performance="low"] body.is-alarm   { background: #ffe4e6; }
html[data-performance="low"] body.is-warning { background: #fff1f2; }
html[data-performance="low"]html[data-theme="dark"] body.is-alarm { background: #881337; }
html[data-performance="low"] .btn-main.btn-guide { box-shadow: 0 0 0 4px rgba(239,68,68,0.9); }
