* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-2: #232730;
  --text: #f0f2f5;
  --muted: #8b94a3;
  --accent: #ff6b35;
  --accent-2: #ffa94d;
  --ok: #4ade80;
  --warn: #facc15;
  --danger: #f87171;
  --border: #2a2f3a;
}
html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Microsoft JhengHei", sans-serif;
  overflow: hidden;
  height: 100%;
  width: 100%;
  user-select: none;
}

.view { display: none; height: 100vh; width: 100vw; flex-direction: column; }
.view.active { display: flex; }

/* ===== Top bar ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.icon-btn {
  background: transparent; border: 0; color: var(--text);
  font-size: 22px; padding: 6px 10px; cursor: pointer; border-radius: 8px;
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn.active { background: var(--accent); color: #fff; }
.icon-btn.active:hover { background: var(--accent-2); }

.container { flex: 1; padding: 20px; overflow-y: auto; }
.container h2 { font-size: 16px; color: var(--muted); margin-bottom: 12px; font-weight: 500; }

/* ===== Menu items ===== */
#menu-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.menu-item {
  background: var(--panel); border-radius: 12px; padding: 14px 16px;
  display: flex; align-items: center; gap: 12px; border: 1px solid var(--border);
}
.menu-item .name { flex: 1; font-weight: 600; }
.menu-item .meta { color: var(--muted); font-size: 13px; }
.menu-item .remove {
  background: transparent; border: 0; color: var(--danger); font-size: 20px; cursor: pointer;
}
.menu-empty { color: var(--muted); text-align: center; padding: 30px; font-size: 14px; }

/* ===== Buttons ===== */
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
button.primary, button.ghost, button.cta {
  border: 0; border-radius: 10px; padding: 12px 18px; font-size: 15px;
  font-weight: 600; cursor: pointer; transition: transform .05s;
}
button.primary { background: var(--accent); color: #fff; }
button.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button.cta {
  width: 100%; padding: 18px; font-size: 18px; background: var(--accent);
  color: #fff; border-radius: 14px;
  box-shadow: 0 6px 20px rgba(255,107,53,.3);
}
button:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; }
button:active:not(:disabled) { transform: scale(.97); }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--panel); width: 100%; max-width: 500px;
  border-radius: 18px 18px 0 0; max-height: 85vh; overflow-y: auto;
  animation: slideUp .2s;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-content header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel);
}
.modal-content h3 { font-size: 17px; }

#picker-categories { padding: 10px; }
.cat-title {
  font-size: 13px; color: var(--muted); padding: 14px 8px 6px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px;
}
.ex-card {
  background: var(--panel-2); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 10px; cursor: pointer; border: 1px solid var(--border);
}
.ex-card:active { background: #2d3340; }
.ex-card .ex-name { flex: 1; font-weight: 600; font-size: 15px; }
.ex-card .stars { font-size: 11px; color: var(--warn); }
.ex-card .ex-hint { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* Form inside modal */
.form { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.form input {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 8px 12px; font-size: 16px;
  width: 90px; text-align: center;
}
.form .hidden { display: none; }

/* ===== Workout view ===== */
.workout-header {
  display: flex; align-items: center; padding: 12px 14px;
  background: var(--panel); border-bottom: 1px solid var(--border); gap: 12px;
}
.workout-title { flex: 1; }
.workout-title #wk-name { font-weight: 700; font-size: 16px; }
.workout-title #wk-progress { font-size: 12px; }
.muted { color: var(--muted); }

.camera-wrap {
  flex: 1; position: relative; background: #000; overflow: hidden;
}
#cam, #overlay {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  object-fit: contain;
}
#cam { background: #000; }
/* #cam mirror is controlled dynamically by pose.js */
#overlay { pointer-events: none; }

.hint {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.65); padding: 8px 14px; border-radius: 20px;
  font-size: 13px; z-index: 10;
}

.voice-help {
  position: absolute; top: 60px; right: 12px;
  background: rgba(0,0,0,.7); border: 1px solid rgba(255,107,53,.6);
  border-radius: 10px; padding: 10px 12px; z-index: 10;
  max-width: 220px;
}
.voice-help .vh-title { font-size: 12px; color: var(--accent); margin-bottom: 6px; font-weight: 600; }
.voice-help .vh-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px;
  font-size: 12px; color: rgba(255,255,255,.9);
}

.big-counter {
  position: absolute; bottom: 30px; left: 0; right: 0;
  text-align: center; font-size: 120px; font-weight: 800;
  color: #fff; text-shadow: 0 4px 20px rgba(0,0,0,.8);
  font-variant-numeric: tabular-nums; line-height: 1; pointer-events: none;
}
.big-target {
  position: absolute; bottom: 14px; left: 0; right: 0;
  text-align: center; font-size: 18px; color: rgba(255,255,255,.8);
  text-shadow: 0 2px 6px rgba(0,0,0,.8); pointer-events: none;
}

.rest {
  position: absolute; inset: 0; background: rgba(15,17,21,.94);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 20;
}
.rest.hidden { display: none; }
.rest-panels {
  display: grid; grid-template-columns: 1fr 1.2fr 1fr;
  gap: 18px; width: 100%; height: 100%;
  padding: 22px; box-sizing: border-box;
  align-items: center;
}
.rest-side {
  background: rgba(255,255,255,.04); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; height: 100%;
  overflow-y: auto; max-height: 80vh;
}
.rest-side-title {
  font-size: 18px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 1.5px; margin-bottom: 14px; font-weight: 600;
}
.rest-center {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
}
.rest-label { font-size: 18px; color: var(--muted); }
.rest-time {
  font-size: 110px; font-weight: 800; color: var(--accent);
  font-variant-numeric: tabular-nums; line-height: 1;
}

.rest-menu-row {
  display: flex; align-items: center; gap: 14px; padding: 20px 14px;
  border-bottom: 1px solid rgba(255,255,255,.05); font-size: 34px;
}
.rest-menu-row:last-child { border-bottom: 0; }
.rest-menu-row.current {
  background: rgba(255,107,53,.12); border-radius: 8px; color: var(--accent);
  font-weight: 700;
}
.rest-menu-row.done { color: var(--muted); text-decoration: line-through; }
.rest-menu-row .rmr-name { flex: 1; }
.rest-menu-row .rmr-meta { font-size: 24px; color: var(--muted); }
.rest-menu-row.current .rmr-meta { color: var(--accent); }

.rest-progress-block {
  padding: 10px 6px; border-bottom: 1px solid rgba(255,255,255,.05);
}
.rest-progress-block:last-child { border-bottom: 0; }
.rpb-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.rpb-value { font-size: 18px; font-weight: 600; }
.rpb-value.big { font-size: 24px; color: var(--accent); }

/* 行動裝置直立時改成上下排，中央時間最大 */
@media (max-width: 720px) {
  .rest-panels {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: 10px; padding: 12px;
  }
  .rest-side { max-height: 30vh; }
  .rest-time { font-size: 80px; }
}

.done {
  position: absolute; inset: 0; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 30; gap: 24px; padding: 30px;
}
.done.hidden { display: none; }
.done h2 { font-size: 28px; }
#done-summary { color: var(--muted); text-align: center; line-height: 1.7; }

.workout-footer {
  display: flex; gap: 10px; padding: 12px 14px; background: var(--panel);
  border-top: 1px solid var(--border);
}
.workout-footer button { flex: 1; }
.manual-tap {
  background: var(--accent) !important; color: #fff;
  font-size: 22px !important; padding: 18px !important;
}

/* ===== History ===== */
.voice-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel-2); margin-bottom: 8px;
}
.voice-row.selected { border-color: var(--accent); background: rgba(255,107,53,.12); }
.voice-row .v-name { flex: 1; font-weight: 600; }
.voice-row .v-lang { color: var(--muted); font-size: 12px; }
.voice-row .v-check { color: var(--accent); font-size: 18px; }
.voice-empty { color: var(--muted); padding: 16px; text-align: center; font-size: 14px; }

.history-day {
  background: var(--panel); border-radius: 12px; padding: 14px 16px;
  margin-bottom: 12px; border: 1px solid var(--border);
}
.history-day h3 { font-size: 15px; margin-bottom: 8px; }
.history-day .row { font-size: 13px; color: var(--muted); padding: 3px 0; }

.flash { animation: flash .3s; }
@keyframes flash { 0% { color: var(--ok); transform: scale(1.15); } 100% { color: #fff; transform: scale(1); } }

.hidden { display: none !important; }
