:root {
  --bg: #0e1117;
  --panel: #171b24;
  --panel-2: #1f2430;
  --text: #eef1f6;
  --text-dim: #8891a3;
  --accent: #4f7cff;
  --warn: #ffb020;
  --danger: #ff4d4f;
  --ok: #2ecc71;
  --digit-w: 15vmin;
  --digit-h: 21vmin;
  --state-color: var(--accent);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  overflow: hidden;
}

.app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 340px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid #262b38;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.25s ease;
}
.sidebar.collapsed {
  margin-left: -340px;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
}
.sidebar-header h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}
.app-name {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 1px;
  margin-bottom: 2px;
}
.day-tabs {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
}
.day-tab {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text-dim);
  text-align: center;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid transparent;
}
.day-tab.active {
  background: rgba(79,124,255,0.15);
  color: var(--text);
  border-color: var(--accent);
}
.agenda-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 16px;
}
.agenda-item {
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 6px;
  cursor: pointer;
  border: 1px solid transparent;
}
.agenda-item:hover { background: var(--panel-2); }
.agenda-item.active {
  background: rgba(79,124,255,0.15);
  border-color: var(--accent);
}
.agenda-item.done { opacity: 0.4; }
.agenda-item.done .ai-title { text-decoration: line-through; }
.agenda-item.break .ai-title { color: var(--text-dim); font-style: italic; }
.ai-time {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
}
.ai-title {
  font-size: 14px;
  font-weight: 600;
  margin: 2px 0;
}
.ai-people {
  font-size: 12px;
  color: var(--text-dim);
}

.icon-btn {
  background: var(--panel-2);
  border: none;
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: #2a3140; }

.sidebar-open-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 5;
  display: none;
}
.sidebar.collapsed ~ .sidebar-open-btn,
.sidebar.collapsed + .sidebar-open-btn {
  display: flex;
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 24px;
  overflow: hidden;
  position: relative;
}

.topbar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.now-title {
  font-size: clamp(18px, 2.4vw, 30px);
  font-weight: 700;
}
.now-people {
  font-size: clamp(13px, 1.4vw, 18px);
  color: var(--text-dim);
  margin-top: 4px;
}
.topbar-actions {
  display: flex;
  gap: 8px;
}

.status-banner-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.status-banner {
  margin-top: 8px;
  padding: 6px 18px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 14px;
  letter-spacing: 1px;
  transition: background 0.3s, color 0.3s;
}

#muteAlertBtn {
  margin-top: 8px;
}
.status-banner.running { background: rgba(79,124,255,0.15); color: var(--accent); }
.status-banner.warning { background: rgba(255,176,32,0.18); color: var(--warn); }
.status-banner.timeup { background: rgba(255,77,79,0.2); color: var(--danger); animation: pulse-bg 1s infinite; }
.status-banner.paused { background: rgba(255,255,255,0.08); color: var(--text-dim); }

@keyframes pulse-bg {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.clock-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.progress-ring {
  position: absolute;
  width: min(58vmin, 620px);
  height: min(58vmin, 620px);
  transform: rotate(-90deg);
}
.progress-ring-bg, .progress-ring-fg {
  fill: none;
  stroke-width: 2.4;
}
.progress-ring-bg { stroke: #232838; }
.progress-ring-fg {
  stroke: var(--state-color);
  stroke-linecap: round;
  stroke-dasharray: 289;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.4s linear, stroke 0.3s;
}

.flip-clock {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 1.2vmin;
}

.flip-colon {
  font-size: calc(var(--digit-h) * 0.55);
  font-weight: 700;
  color: var(--text-dim);
  padding-bottom: 0.5vmin;
}

/* Flip digit card */
.flip-digit {
  position: relative;
  width: var(--digit-w);
  height: var(--digit-h);
  perspective: 60vmin;
}
.flip-digit .static {
  position: absolute;
  left: 0; width: 100%; height: 50%;
  overflow: hidden;
  background: #1a1f2b;
  border-radius: 4px;
}
.flip-digit .static.top { top: 0; border-radius: 6px 6px 0 0; }
.flip-digit .static.bottom { bottom: 0; border-radius: 0 0 6px 6px; }
.flip-digit .static span,
.flip-digit .leaf .face span {
  position: absolute;
  left: 0; width: 100%;
  height: var(--digit-h);
  line-height: var(--digit-h);
  font-size: calc(var(--digit-h) * 0.72);
  font-weight: 700;
  text-align: center;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.flip-digit .static.top span { top: 0; }
.flip-digit .static.bottom span { top: calc(var(--digit-h) * -0.5); }

.flip-digit::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: calc(50% - 1px); height: 2px;
  background: rgba(0,0,0,0.4);
  z-index: 3;
}

.flip-digit .leaf {
  position: absolute;
  left: 0; width: 100%; height: 50%;
  transform-style: preserve-3d;
  z-index: 2;
}
.flip-digit .leaf.leaf-top {
  top: 0;
  transform-origin: bottom center;
}
.flip-digit .leaf.leaf-bottom {
  bottom: 0;
  transform-origin: top center;
  transform: rotateX(90deg);
}
.flip-digit .leaf .face {
  position: absolute;
  left: 0; top: 0; width: 100%; height: 100%;
  overflow: hidden;
  backface-visibility: hidden;
  background: #232938;
  border-radius: 6px 6px 0 0;
}
.flip-digit .leaf.leaf-bottom .face { border-radius: 0 0 6px 6px; }
.flip-digit .leaf.leaf-top .face span { top: 0; }
.flip-digit .leaf.leaf-bottom .face span { top: calc(var(--digit-h) * -0.5); }

.flip-digit.flipping .leaf-top {
  animation: flipTopAnim 0.5s cubic-bezier(.4,0,.2,1) forwards;
}
.flip-digit.flipping .leaf-bottom {
  animation: flipBottomAnim 0.5s cubic-bezier(.4,0,.2,1) forwards;
}
@keyframes flipTopAnim {
  0% { transform: rotateX(0deg); }
  100% { transform: rotateX(-90deg); }
}
@keyframes flipBottomAnim {
  0%, 50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}

/* ---------- Controls ---------- */
.controls {
  display: flex;
  gap: 14px;
  margin-bottom: 12px;
}
.btn {
  border: none;
  border-radius: 12px;
  padding: 16px 26px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
}
.btn-primary { background: var(--accent); min-width: 160px; }
.btn-primary.running { background: var(--warn); color: #21232a; }
.btn-secondary { background: var(--panel-2); color: var(--text); }
.btn:active { transform: scale(0.97); }
.btn-sm { padding: 8px 14px; font-size: 14px; }

.manual-adjust {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 6px;
}
.chip {
  background: var(--panel-2);
  color: var(--text);
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
}

/* ---------- Settings overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.overlay.open { display: flex; }
.panel {
  background: var(--panel);
  border-radius: 16px;
  padding: 24px;
  width: min(420px, 90vw);
}
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.panel-header h2 { margin: 0; font-size: 18px; }
.field {
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 13px;
  color: var(--text-dim);
}
.field input[type="number"],
.field input[type="file"] {
  background: var(--panel-2);
  border: 1px solid #2a3140;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}
.field input[type="range"] { width: 100%; }
.hint { font-size: 12px; color: var(--text-dim); }
.version-tag {
  text-align: right;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

.panel-wide { width: min(760px, 92vw); max-height: 86vh; display: flex; flex-direction: column; }
.edit-day-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.edit-day-row .day-tabs { flex: 1; padding: 0; min-width: 200px; }
.btn-secondary.danger { background: rgba(255,77,79,0.15); color: var(--danger); }
.edit-items-list {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}
.edit-item-row {
  display: grid;
  grid-template-columns: 96px 70px 1.4fr 1fr 90px auto;
  gap: 6px;
  align-items: center;
  background: var(--panel-2);
  border-radius: 8px;
  padding: 8px;
}
.edit-item-row input, .edit-item-row select {
  background: #12151d;
  border: 1px solid #2a3140;
  color: var(--text);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  width: 100%;
}
.edit-item-row .row-actions {
  display: flex;
  gap: 4px;
}
.edit-item-row .row-actions button {
  background: #12151d;
  border: none;
  color: var(--text-dim);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.edit-item-row .row-actions button:hover { background: #232938; color: var(--text); }
.edit-item-row .row-actions button.del { color: var(--danger); }
.edit-footer {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
@media (max-width: 700px) {
  .edit-item-row { grid-template-columns: 1fr 1fr; }
}

/* Fullscreen tweaks */
:fullscreen .sidebar,
:fullscreen .topbar-actions,
:fullscreen .manual-adjust { display: none; }
:fullscreen .main { padding-top: 40px; }

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 6; height: 100%; }
  --digit-w: 20vmin;
}
