/* ========== 字体 ========== */
@font-face {
  font-family: 'Zpix';
  src: url('/fonts/zpix.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'Press Start 2P';
  src: url('/fonts/PressStart2P-Regular.ttf') format('truetype');
  font-display: swap;
}

/* ========== 基础 ========== */
:root {
  --ink: #1b1035;
  --panel: rgba(24, 13, 47, 0.92);
  --panel-border: #f5e8c8;
  --cream: #f5e8c8;
  --yellow: #ffd166;
  --red: #ff5d73;
  --green: #57d9a3;
  --blue: #5aa9ff;
  --pink: #ff9ecb;
  --mode-color: var(--red);
  --shadow: rgba(0, 0, 0, 0.55);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Zpix', 'Press Start 2P', 'Microsoft YaHei', monospace;
  color: var(--cream);
  user-select: none;
  -webkit-user-select: none;
}

button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input[type="number"] {
  font-family: 'Press Start 2P', monospace;
  background: #120a26;
  color: var(--yellow);
  border: 2px solid #6d5aa8;
  padding: 4px 6px;
  width: 64px;
  text-align: center;
}

/* ========== 背景 ========== */
#bgStage { position: fixed; inset: 0; z-index: 0; }
#bgStage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  transition: opacity 0.3s ease;
}
#bgFreeze {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

/* ========== 像素按钮通用 ========== */
.pixel-btn {
  display: inline-block;
  background: #2a1a4d;
  color: var(--cream);
  border: 3px solid var(--panel-border);
  box-shadow: 0 4px 0 var(--shadow), inset 0 0 0 2px #120a26;
  padding: 6px 10px;
  font-size: 13px;
  line-height: 1.2;
  text-align: center;
  position: relative;
  top: 0;
  transition: none;
}
.pixel-btn:hover { background: #3d2870; color: var(--yellow); }
.pixel-btn:active {
  top: 3px;
  box-shadow: 0 1px 0 var(--shadow), inset 0 0 0 2px #120a26;
}
.pixel-btn.active { background: #5939a8; color: var(--yellow); box-shadow: 0 4px 0 var(--shadow), inset 0 0 0 3px var(--yellow); }
.pixel-btn:disabled { opacity: 0.45; cursor: default; }

/* ========== 右上悬浮按钮 ========== */
.float-btn {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 50;
  font-size: 16px;
  width: 44px;
  height: 44px;
  padding: 0;
}

/* ========== 联系方式&备案按钮（底部工具栏） ========== */
#beianBtn {
  white-space: nowrap;
}

/* ========== 专注模式：隐藏/显示全部 UI ========== */
#uiToggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 55;
  font-size: 12px;
  padding: 5px 10px;
  transition: opacity 0.3s ease;
}
/* 专注模式下按钮几乎透明，难以察觉；悬停/聚焦时恢复清晰 */
body.ui-hidden #uiToggle {
  opacity: 0.15;
}
body.ui-hidden #uiToggle:hover,
body.ui-hidden #uiToggle:focus-visible {
  opacity: 1;
}
body.ui-hidden #bottomBar,
body.ui-hidden #modeTabs,
body.ui-hidden #bgToggle,
body.ui-hidden #beianBtn,
body.ui-hidden #playlistPanel,
body.ui-hidden #settingsOverlay,
body.ui-hidden #plansOverlay,
body.ui-hidden #beianOverlay,
body.ui-hidden #lapsOverlay {
  display: none !important;
}

/* ========== 模式切换 ========== */
#modeTabs {
  position: fixed;
  top: 12px;
  left: 66px;
  z-index: 50;
  display: flex;
  gap: 6px;
}
.mode-tab { font-size: 13px; }

/* ========== 圆窗倒计时 ========== */
#windowCircle {
  --r: 160px;               /* JS 未运行时的兜底半径 */
  width: 340px;
  height: 340px;
  position: fixed;
  z-index: 20;
  border-radius: 50%;
  overflow: hidden;
  cursor: move;
  background:
    radial-gradient(circle at 50% 42%, rgba(20, 10, 40, 0.52) 0%, rgba(12, 6, 28, 0.72) 72%, rgba(8, 4, 20, 0.88) 100%);
  box-shadow:
    0 0 0 calc(var(--r) * 0.055) #4a2c1f,
    0 0 0 calc(var(--r) * 0.085) #2b1a12,
    0 0 0 calc(var(--r) * 0.105) #1c110b,
    inset 0 0 calc(var(--r) * 0.12) rgba(0, 0, 0, 0.55);
}
#windowInner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--r) * 0.035);
  padding: calc(var(--r) * 0.34) 0 calc(var(--r) * 0.05);
}

#timerRing {
  position: absolute;
  inset: calc(var(--r) * 0.065);
  width: auto;
  height: auto;
  transform: rotate(-90deg);
  pointer-events: none;
}
#ringTrack, #ringBar { fill: none; stroke-width: 5; }
#ringTrack { stroke: rgba(245, 232, 200, 0.22); }
#ringBar {
  stroke: var(--mode-color);
  stroke-linecap: butt;
  stroke-dasharray: 578;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.25s linear;
  filter: drop-shadow(0 0 3px var(--mode-color));
}

#timerMode {
  position: relative;
  z-index: 2;
  font-size: calc(var(--r) * 0.105);
  color: var(--yellow);
  letter-spacing: 0.1em;
  text-shadow: 2px 2px 0 var(--ink);
}
#timerDigits {
  position: relative;
  z-index: 2;
  font-family: 'Press Start 2P', 'Zpix', monospace;
  font-size: calc(var(--r) * 0.30);
  color: var(--cream);
  letter-spacing: 0.02em;
  text-shadow:
    3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 3px 0 var(--ink), 0 -3px 0 var(--ink),
    3px 3px 0 var(--ink), -3px 3px 0 var(--ink), 3px -3px 0 var(--ink), -3px -3px 0 var(--ink),
    0 0 8px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
}
#timerDigits.digits-stopwatch { font-size: calc(var(--r) * 0.22); }

#sessionInfo, #lapHint {
  position: relative;
  z-index: 2;
  font-size: calc(var(--r) * 0.075);
  color: var(--cream);
  opacity: 0.92;
  text-shadow: 2px 2px 0 var(--ink);
}
.focus-input {
  position: relative;
  z-index: 2;
  width: 80%;
  max-width: calc(var(--r) * 1.2);
  font-family: inherit;
  font-size: calc(var(--r) * 0.072);
  color: var(--cream);
  background: rgba(18, 10, 38, 0.62);
  border: 2px solid rgba(245, 232, 200, 0.5);
  padding: calc(var(--r) * 0.018) calc(var(--r) * 0.035);
  text-align: center;
  outline: none;
  text-shadow: 1px 1px 0 var(--ink);
}
.focus-input::placeholder { color: rgba(245, 232, 200, 0.42); }
.focus-input:focus { border-color: var(--yellow); background: rgba(18, 10, 38, 0.85); }
#focusText {
  position: relative;
  z-index: 2;
  max-width: 84%;
  font-size: calc(var(--r) * 0.075);
  color: var(--cream);
  text-shadow: 1px 1px 0 var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.95;
}

.window-btn {
  position: relative;
  z-index: 3;
  font-size: calc(var(--r) * 0.085);
  padding: calc(var(--r) * 0.03) calc(var(--r) * 0.07);
  border-width: calc(max(2px, var(--r) * 0.015));
  box-shadow: 0 calc(var(--r) * 0.025) 0 var(--shadow), inset 0 0 0 calc(var(--r) * 0.01) #120a26;
  transition: opacity 0.3s ease;
}
.window-btn:active { top: calc(var(--r) * 0.02); box-shadow: 0 calc(var(--r) * 0.006) 0 var(--shadow), inset 0 0 0 calc(var(--r) * 0.01) #120a26; }
/* 专注模式下番茄钟按钮同样几乎透明，悬停/聚焦时恢复清晰 */
body.ui-hidden #windowBtn {
  opacity: 0.15;
}
body.ui-hidden #windowBtn:hover,
body.ui-hidden #windowBtn:focus-visible {
  opacity: 1;
}

/* ========== 底部控制栏 ========== */
#bottomBar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px;
  padding: 10px 14px 12px;
  background: var(--panel);
  border-top: 4px solid var(--panel-border);
  box-shadow: 0 -4px 0 rgba(0, 0, 0, 0.35), inset 0 0 0 2px #120a26;
  backdrop-filter: blur(2px);
}

#playerSection {
  flex: 1 1 420px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  min-width: 0;
}

#nowPlaying {
  min-width: 180px;
  max-width: 320px;
  overflow: hidden;
  white-space: nowrap;
}
#npPlaylist {
  display: block;
  font-size: 11px;
  color: var(--pink);
  text-shadow: 1px 1px 0 var(--ink);
}
#npTrack {
  display: block;
  font-size: 14px;
  color: var(--cream);
  text-shadow: 1px 1px 0 var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
}

#playerControls { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn.big { width: 46px; height: 46px; font-size: 18px; }
.icon-btn.liked { color: var(--red); background: #3d1430; }
/* 图标文字包在 span 里单独偏移，不移动整个按钮（em 单位随字号缩放）：
   ▶ 在字体中视觉重心偏高 0.25em（实测），下移补偿；⏸ 偏低 0.056em，上移补偿 */
#btnPlay .icon { display: inline-block; }
#btnPlay:not(.playing) .icon { transform: translateY(0.25em); }
#btnPlay.playing .icon { transform: translateY(-0.056em); }

#progressRow { display: flex; align-items: center; gap: 8px; flex: 1 1 240px; min-width: 180px; }
#progressRow span { font-size: 11px; font-family: 'Press Start 2P', monospace; min-width: 42px; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 12px;
  background: #120a26;
  border: 2px solid #6d5aa8;
  outline: none;
  flex: 1;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 20px;
  background: var(--yellow);
  border: 2px solid var(--cream);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 20px;
  background: var(--yellow);
  border: 2px solid var(--cream);
  border-radius: 0;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

#volumeRow { display: flex; align-items: center; gap: 6px; width: 150px; }
#volIcon { font-size: 12px; color: var(--yellow); }
#volume { flex: 1; }

#timerSection {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, auto);
  align-items: center;
  gap: 8px 6px;
}
#timerSection #btnPlaylist { grid-row: 1; grid-column: 1; }
#timerSection #btnTimerStart { grid-row: 1; grid-column: 2; }
#timerSection #btnTimerReset { grid-row: 1; grid-column: 3; }
#timerSection #btnTimerSkip, #timerSection #btnLap { grid-row: 1; grid-column: 4; }
#timerSection #btnPlans { grid-row: 2; grid-column: 1; }
#timerSection #btnSettings { grid-row: 2; grid-column: 2; }
#timerSection #beianBtn { grid-row: 2; grid-column: 3 / 5; justify-self: end; }
.action-btn { font-size: 13px; padding: 6px 12px; }

/* ========== 播放列表面板 ========== */
#playlistPanel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 84px;
  z-index: 45;
  max-width: 640px;
  margin: 0 auto;
  background: var(--panel);
  border: 3px solid var(--panel-border);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.5), inset 0 0 0 2px #120a26;
  display: flex;
  flex-direction: column;
  max-height: 46vh;
}
#plHeader, .panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #2a1a4d;
  border-bottom: 3px solid #6d5aa8;
  font-size: 14px;
  color: var(--yellow);
}
.mini-btn { padding: 3px 8px; font-size: 12px; }
.pl-header-btns { display: flex; gap: 6px; }

#plTabs {
  display: flex;
  gap: 4px;
  padding: 8px 10px 0;
  flex-wrap: wrap;
}
#plTabs .pixel-btn { font-size: 12px; padding: 4px 8px; border-width: 2px; }

#plList {
  overflow-y: auto;
  padding: 8px 10px 12px;
  max-height: 36vh;
}
#plList::-webkit-scrollbar { width: 10px; }
#plList::-webkit-scrollbar-track { background: #120a26; }
#plList::-webkit-scrollbar-thumb { background: #6d5aa8; border: 2px solid #120a26; }

.track-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px;
  border-bottom: 2px dashed rgba(245, 232, 200, 0.18);
  cursor: pointer;
  font-size: 13px;
}
.track-row:hover { background: rgba(89, 57, 168, 0.5); }
.track-row.playing { background: rgba(89, 57, 168, 0.7); color: var(--yellow); }
.track-row .idx { color: var(--pink); min-width: 26px; text-align: right; font-size: 11px; }
.track-row .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-row .heart {
  font-size: 15px;
  color: #8d7bb5;
  padding: 2px 6px;
}
.track-row .heart.on { color: var(--red); }
.pl-empty { padding: 18px; text-align: center; color: #b7a6dd; font-size: 13px; }
.pl-folder-bar {
  display: flex;
  justify-content: flex-end;
  padding: 6px 2px 8px;
  border-bottom: 2px dashed rgba(245, 232, 200, 0.2);
  margin-bottom: 4px;
}
.local-hint {
  padding: 6px 8px 8px;
  font-size: 11px;
  color: #b7a6dd;
  border-bottom: 2px dashed rgba(245, 232, 200, 0.18);
}

/* ========== 设置面板 ========== */
#settingsOverlay, #lapsOverlay, #plansOverlay, #beianOverlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(5, 2, 14, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
}
#settingsPanel {
  width: min(560px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border: 3px solid var(--panel-border);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.55), inset 0 0 0 2px #120a26;
}
.panel-section {
  padding: 12px 14px;
  border-bottom: 2px dashed rgba(245, 232, 200, 0.2);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.section-title {
  font-size: 13px;
  color: var(--pink);
  letter-spacing: 0.08em;
  text-shadow: 1px 1px 0 var(--ink);
}
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.setting-input { display: flex; align-items: center; gap: 8px; color: #b7a6dd; font-size: 12px; }
#resButtons { flex-wrap: wrap; justify-content: flex-end; }
.checkbox-row { justify-content: flex-start; gap: 8px; cursor: pointer; }
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--yellow); }
.hint { font-size: 11px; color: #b7a6dd; line-height: 1.7; }
.footer-note { font-size: 11px; color: #8d7bb5; line-height: 1.5; gap: 2px; }
.footer-note a { color: var(--yellow); text-decoration: underline; cursor: pointer; }
.footer-note a:hover { color: var(--cream); }
.footer-note .beian { margin-top: 16px; }

/* ========== 任务计划面板 ========== */
#plansPanel {
  width: min(600px, 94vw);
  max-height: 88vh;
  background: var(--panel);
  border: 3px solid var(--panel-border);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.55), inset 0 0 0 2px #120a26;
  display: flex;
  flex-direction: column;
}
#plansTabs {
  display: flex;
  gap: 6px;
  padding: 8px 10px 0;
}
#plansTabs .pixel-btn { font-size: 12px; padding: 4px 10px; border-width: 2px; }
#plansBody {
  overflow-y: auto;
  padding: 10px 10px 12px;
  max-height: 64vh;
}
#plansBody::-webkit-scrollbar { width: 10px; }
#plansBody::-webkit-scrollbar-track { background: #120a26; }
#plansBody::-webkit-scrollbar-thumb { background: #6d5aa8; border: 2px solid #120a26; }

#planAddRow {
  display: flex;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 2px dashed rgba(245, 232, 200, 0.2);
}
#planAddRow input[type="text"] {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 13px;
  color: var(--cream);
  background: #120a26;
  border: 2px solid #6d5aa8;
  padding: 5px 8px;
  outline: none;
}
#planAddRow input[type="text"]::placeholder { color: #8d7bb5; }
#planAddRow input[type="text"]:focus { border-color: var(--yellow); }
#planAddRow input[type="number"] { width: 58px; font-size: 12px; }

.plan-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 4px;
  border-bottom: 2px dashed rgba(245, 232, 200, 0.18);
  font-size: 13px;
}
.plan-row.done { opacity: 0.55; }
.plan-row.done .plan-title { text-decoration: line-through; }
.plan-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-meta { color: var(--pink); font-size: 11px; white-space: nowrap; }
.plan-row .mini-btn { font-size: 11px; padding: 2px 7px; }
.plan-row .plan-del { color: #ff9b9b; }

#recordFooter { padding-top: 10px; text-align: center; }
.record-row {
  display: grid;
  grid-template-columns: 76px 110px 52px 1fr;
  gap: 8px;
  align-items: center;
  padding: 7px 4px;
  border-bottom: 2px dashed rgba(245, 232, 200, 0.18);
  font-size: 12px;
}
.record-row .record-date { color: var(--yellow); }
.record-row .record-time { color: var(--cream); font-family: 'Press Start 2P', monospace; font-size: 10px; }
.record-row .record-dur { color: var(--pink); }
.record-row .record-task { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ========== 备案与联系方式面板 ========== */
#beianPanel {
  width: min(420px, 90vw);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border: 3px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  padding: 12px;
}

/* ========== 秒表圈数 ========== */
#lapsPanel {
  width: min(420px, 92vw);
  max-height: 70vh;
  background: var(--panel);
  border: 3px solid var(--panel-border);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.55), inset 0 0 0 2px #120a26;
  display: flex;
  flex-direction: column;
}
#lapsList { overflow-y: auto; padding: 8px 12px; }
.lap-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 4px;
  border-bottom: 2px dashed rgba(245, 232, 200, 0.18);
  font-size: 13px;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
}
.lap-row .lap-no { color: var(--pink); }

/* ========== 彩蛋：全屏黑幕 ========== */
#easterEggOverlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#easterEggBox {
  position: relative;
  box-sizing: border-box;
  width: min(88vw, 780px);
  border: 4px solid #fff;
  background: #000;
  color: #fff;
  padding: 52px 46px 42px;
  box-shadow: 0 0 60px rgba(255, 255, 255, 0.18);
}
#easterEggBox .msg {
  font-size: clamp(30px, 6vw, 54px);
  line-height: 1.8;
  text-align: left;
  text-shadow: 0 0 14px rgba(255, 255, 255, 0.4);
}
#easterEggBox .blank { height: 1em; }
#easterEggBox .l2 { margin-left: 1em; } /* 让「你」与「找」竖直对齐 */
#easterEggClose {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 46px;
  height: 46px;
  background: #000;
  border: 3px solid #fff;
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
#easterEggClose:hover { background: #222; }

/* ========== 响应式 ========== */
@media (max-width: 760px), (pointer: coarse) and (max-height: 620px) {
  #modeTabs { left: 12px; top: 64px; }
  #modeTabs .mode-tab { font-size: 12px; padding: 5px 8px; }

  /* 底部控制栏：改为纵向紧凑布局，可滚动 */
  #bottomBar {
    flex-direction: column;
    gap: 6px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    max-height: 46vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #playerSection {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    flex: none;
  }
  #nowPlaying { max-width: 100%; min-width: 0; }
  #npTrack { font-size: 13px; }
  #playerControls { justify-content: center; gap: 5px; }
  .icon-btn { width: 34px; height: 34px; font-size: 13px; }
  .icon-btn.big { width: 42px; height: 42px; font-size: 16px; }
  #progressRow { min-width: 0; flex: 1 1 auto; }
  #volumeRow { width: 100%; }

  #timerSection {
    justify-content: center;
    gap: 6px 5px;
  }
  .action-btn { padding: 5px 10px; font-size: 12px; }

  /* 播放列表面板：底部全宽抽屉样式 */
  #playlistPanel {
    left: 6px;
    right: 6px;
    bottom: 6px;
    max-width: none;
    max-height: 62vh;
  }
  #plList { max-height: 46vh; }

  /* 设置项换行，避免分/秒输入框溢出 */
  .setting-row { flex-wrap: wrap; }
  .setting-input { flex-wrap: wrap; justify-content: flex-end; }

  /* 计划面板：窄屏换行 */
  #planAddRow { flex-wrap: wrap; }
  #planAddRow input[type="text"] { flex: 1 1 100%; }
  .record-row { grid-template-columns: 1fr 1fr; }

  /* 触摸拖动优化 */
  #windowCircle { --r: 120px; width: 250px; height: 250px; touch-action: none; }
}
