* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0d1117;
  --panel: #171d26;
  --panel-soft: #121821;
  --border: #2c3645;
  --text: #f0f4f8;
  --muted: #9ba7b6;
  --accent: #79a7ff;
  --accent-strong: #9dbbff;
  --green: #5fc989;
  --gold: #d7b56d;
  --red: #df7777;
  --shadow: rgba(0, 0, 0, 0.24);
}

html {
  background: var(--bg);
}

body {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(121, 167, 255, 0.08), transparent 280px),
    var(--bg);
  color: var(--text);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.timer-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.topbar,
.clock-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.clock-head {
  align-items: flex-start;
  justify-content: space-between;
}

.screen-mode-tab {
  display: none;
  width: 38px;
  height: 38px;
  min-height: 38px;
  border: 1px solid rgba(155, 167, 182, 0.28);
  border-radius: 999px;
  background: rgba(18, 24, 33, 0.56);
  color: var(--muted);
  padding: 0;
}

.screen-mode-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.screen-mode-icon-compress {
  display: none;
}

.clock-screen-mode .screen-mode-icon-expand {
  display: none;
}

.clock-screen-mode .screen-mode-icon-compress {
  display: block;
}

.contact-tag {
  min-height: 30px;
  border: 1px solid rgba(155, 167, 182, 0.28);
  border-radius: 999px;
  background: rgba(18, 24, 33, 0.56);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 0 10px;
  white-space: nowrap;
}

.eyebrow {
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 4px;
  text-transform: uppercase;
}

h1 {
  font-size: 28px;
  line-height: 1.12;
  font-weight: 800;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

.ghost-link,
.icon-text-btn,
.small-btn,
.primary-btn,
.secondary-btn,
.danger-btn,
.template-btn {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--panel-soft);
  text-decoration: none;
  font-weight: 700;
  transition: transform 0.12s ease, border-color 0.18s ease, background-color 0.18s ease;
}

.ghost-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  color: var(--muted);
  white-space: nowrap;
}

.icon-text-btn {
  width: auto;
  padding: 0 14px;
  white-space: nowrap;
}

.small-btn {
  width: auto;
  min-height: 38px;
  padding: 0 12px;
  color: var(--accent-strong);
}

.primary-btn,
.secondary-btn,
.danger-btn {
  width: 100%;
  padding: 13px 14px;
}

.primary-btn {
  border-color: rgba(95, 201, 137, 0.55);
  background: linear-gradient(180deg, #65d190, #4fb978);
  color: #07160e;
}

.secondary-btn {
  background: rgba(23, 29, 38, 0.95);
}

.danger-btn {
  border-color: rgba(223, 119, 119, 0.55);
  background: rgba(223, 119, 119, 0.14);
  color: #ffb3b3;
}

button:active,
.ghost-link:active {
  transform: translateY(1px);
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.panel {
  background: rgba(23, 29, 38, 0.96);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 48px var(--shadow);
  margin-bottom: 12px;
  padding: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.template-list {
  display: grid;
  gap: 8px;
}

.template-btn {
  padding: 12px;
  text-align: left;
}

.template-btn.active {
  border-color: var(--accent);
  background: rgba(121, 167, 255, 0.13);
}

.template-name {
  display: block;
  font-size: 14px;
}

.template-meta {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.template-empty {
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  font-size: 13px;
}

.template-name-field {
  display: grid;
  grid-template-columns: minmax(54px, 0.32fr) minmax(0, 1fr);
  align-items: end;
  gap: 8px;
}

.template-section-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.1;
}

.template-select-btn {
  min-height: 44px;
  padding: 11px 8px;
}

.template-input-wrap {
  position: relative;
  display: block;
}

.template-floating-label {
  position: absolute;
  left: 11px;
  top: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.template-name-field input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 18px 10px 6px;
}

.template-name-field input::placeholder {
  color: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.level-list-head,
.level-row {
  display: grid;
  grid-template-columns: 48px minmax(56px, 0.75fr) minmax(64px, 1fr) minmax(64px, 1fr) minmax(58px, 0.8fr) 76px;
  gap: 6px;
  align-items: center;
}

.level-list-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
  padding: 0 2px;
}

.level-list {
  display: grid;
  gap: 8px;
}

.level-row {
  min-height: 46px;
}

.level-index {
  color: var(--gold);
  font-size: 13px;
  font-weight: 800;
}

.level-row.break-row .level-index {
  color: var(--accent-strong);
  font-size: 11px;
}

.level-field {
  min-width: 0;
}

.level-field span {
  display: none;
}

.level-input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 8px;
  text-align: center;
}

.level-actions {
  display: grid;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  justify-content: flex-end;
  justify-items: end;
  gap: 6px;
}

.insert-level-btn,
.remove-level-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-weight: 800;
}

.insert-level-btn {
  border: 1px solid rgba(121, 167, 255, 0.55);
  background: rgba(121, 167, 255, 0.12);
  color: var(--accent-strong);
}

.remove-level-btn {
  border: 1px solid rgba(223, 119, 119, 0.5);
  background: rgba(223, 119, 119, 0.1);
  color: #ffb3b3;
}

.status-line {
  min-height: 24px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  margin: 8px 2px 12px;
}

.status-line.warn {
  color: #ffb3b3;
}

.status-line.ok {
  color: #9be0b6;
}

.setup-status-line {
  height: 0;
  min-height: 0;
  margin: 0;
  overflow: hidden;
}

.clock-status-line {
  height: 0;
  min-height: 0;
  margin: 0;
  overflow: hidden;
}

.setup-toast {
  position: fixed;
  left: 50%;
  bottom: calc(170px + env(safe-area-inset-bottom));
  z-index: 10;
  width: min(calc(100% - 32px), 680px);
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(23, 29, 38, 0.96);
  box-shadow: 0 18px 48px var(--shadow);
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, 10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.setup-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.setup-toast.ok {
  border-color: rgba(95, 201, 137, 0.6);
  background: rgba(95, 201, 137, 0.96);
  color: #07160e;
}

.setup-toast.warn {
  border-color: rgba(223, 119, 119, 0.65);
  background: rgba(223, 119, 119, 0.96);
  color: #fff7f7;
}

.action-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  position: sticky;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 5;
  background: linear-gradient(180deg, transparent, var(--bg) 18px);
  padding-top: 14px;
}

.save-template-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(62px, 0.28fr) minmax(62px, 0.28fr);
  align-items: end;
  gap: 8px;
}

.action-template-name {
  min-width: 0;
}

.action-template-name input {
  min-height: 44px;
}

.template-action-btn {
  min-height: 44px;
  padding: 11px 8px;
}

.template-picker-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(7, 10, 15, 0.62);
}

.template-picker {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 21;
  width: min(100%, 760px);
  max-height: min(70vh, 520px);
  transform: translateX(-50%);
  display: grid;
  gap: 12px;
  overflow: auto;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: #121821;
  box-shadow: 0 -18px 48px var(--shadow);
  padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
}

.template-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.template-picker-head p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.author-contact-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(7, 10, 15, 0.56);
}

.author-contact-dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 31;
  width: min(calc(100% - 32px), 360px);
  transform: translate(-50%, -50%);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #121821;
  box-shadow: 0 18px 48px var(--shadow);
  padding: 16px;
}

.author-contact-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.author-contact-dialog p {
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.45;
}

.author-wechat {
  margin-top: 8px;
  color: var(--gold) !important;
  font-variant-numeric: tabular-nums;
}

.author-wechat-btn {
  min-height: auto;
  border: 0;
  border-bottom: 1px solid rgba(215, 181, 109, 0.55);
  border-radius: 0;
  background: transparent;
  color: var(--gold);
  font: inherit;
  font-weight: 800;
  line-height: 1.25;
  padding: 0 1px 1px;
}

.author-copy-status {
  min-height: 20px;
  margin-top: 10px;
  color: var(--green) !important;
  font-size: 13px !important;
  font-weight: 700 !important;
}

.clock-face {
  min-height: 230px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #101720;
  box-shadow: 0 18px 48px var(--shadow);
  padding: 22px;
  margin-bottom: 12px;
}

.countdown {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 76px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  margin-top: 20px;
}

.progress-track {
  height: 8px;
  border-radius: 8px;
  background: #252e3b;
  overflow: hidden;
  margin-top: 0;
}

.progress-fill {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--green), var(--accent));
  transition: width 0.25s linear;
}

.clock-state {
  color: var(--gold);
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  margin-top: 14px;
  min-height: 20px;
  text-transform: uppercase;
}

.blind-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
}

.blind-panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 8px;
  text-align: center;
}

.blind-panel.current {
  border-color: rgba(215, 181, 109, 0.48);
  background: rgba(215, 181, 109, 0.08);
}

.blind-panel p {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 6px;
  white-space: nowrap;
}

.blind-value {
  color: var(--text);
  font-size: 16px;
  font-weight: 900;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.blind-panel.current .blind-value {
  font-size: 18px;
}

.blind-meta {
  color: var(--gold);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.15;
  margin-top: 5px;
  min-height: 14px;
  overflow-wrap: anywhere;
}

.level-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.level-controls .secondary-btn,
.level-controls .danger-btn {
  min-height: 42px;
  padding: 10px 6px;
  font-size: 13px;
  white-space: nowrap;
}

.clock-controls {
  display: block;
}

@media (min-width: 680px) {
  .timer-shell {
    padding-left: 24px;
    padding-right: 24px;
  }

  .countdown {
    font-size: 104px;
  }

  .clock-face {
    min-height: 280px;
  }

  .blind-strip {
    gap: 10px;
  }

  .level-controls {
    gap: 10px;
  }

  .blind-panel {
    padding: 12px 10px;
  }

  .blind-value {
    font-size: 20px;
  }

  .blind-panel.current .blind-value {
    font-size: 24px;
  }

  .screen-mode-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

@media (min-width: 980px) {
  body.clock-screen-mode {
    overflow: hidden;
  }

  body.clock-screen-mode .timer-shell {
    width: min(100%, 1320px);
    padding: clamp(20px, 2.2vh, 34px) clamp(24px, 4vw, 72px);
  }

  body.clock-screen-mode .clock-head {
    margin-bottom: clamp(16px, 2vh, 28px);
  }

  body.clock-screen-mode .clock-face {
    min-height: 0;
    padding: clamp(26px, 3vw, 46px);
  }

  body.clock-screen-mode .progress-track {
    height: 12px;
  }

  body.clock-screen-mode .clock-state {
    margin-top: clamp(18px, 2.1vh, 28px);
    font-size: clamp(20px, 1.6vw, 30px);
  }

  body.clock-screen-mode .countdown {
    margin-top: clamp(22px, 2.6vh, 40px);
    font-size: clamp(132px, 15vw, 230px);
  }

  body.clock-screen-mode .blind-strip {
    gap: clamp(14px, 1.5vw, 22px);
    margin-top: clamp(26px, 3vh, 44px);
  }

  body.clock-screen-mode .blind-panel {
    padding: clamp(18px, 2vw, 28px) clamp(12px, 1.5vw, 20px);
  }

  body.clock-screen-mode .blind-panel p {
    font-size: clamp(14px, 1vw, 18px);
    margin-bottom: 10px;
  }

  body.clock-screen-mode .blind-value {
    font-size: clamp(28px, 3vw, 50px);
  }

  body.clock-screen-mode .blind-panel.current .blind-value {
    font-size: clamp(34px, 3.6vw, 60px);
  }

  body.clock-screen-mode .blind-meta {
    font-size: clamp(14px, 1vw, 18px);
    margin-top: 10px;
  }

  body.clock-screen-mode .level-controls {
    gap: clamp(14px, 1.5vw, 22px);
    margin-top: clamp(14px, 1.8vh, 24px);
  }

  body.clock-screen-mode .level-controls .secondary-btn,
  body.clock-screen-mode .level-controls .danger-btn,
  body.clock-screen-mode .clock-controls .primary-btn {
    min-height: clamp(56px, 6vh, 78px);
    font-size: clamp(18px, 1.4vw, 26px);
  }

  body.clock-screen-mode .clock-controls {
    margin-top: clamp(18px, 2.4vh, 34px);
  }
}

@media (max-width: 520px) {
  .level-list-head {
    display: none;
  }

  .level-row {
    grid-template-columns: 44px repeat(2, minmax(0, 1fr)) 38px;
    gap: 7px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(18, 24, 33, 0.75);
  }

  .level-index {
    grid-column: 1;
    grid-row: 1 / 3;
  }

  .field-minutes {
    grid-column: 2;
    grid-row: 1;
  }

  .field-sb {
    grid-column: 3;
    grid-row: 1;
  }

  .field-bb {
    grid-column: 2;
    grid-row: 2;
  }

  .field-ante {
    grid-column: 3;
    grid-row: 2;
  }

  .level-field {
    display: grid;
    gap: 4px;
  }

  .level-field span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
  }

  .level-actions {
    grid-column: 4;
    grid-row: 1 / 3;
  }

  .insert-level-btn,
  .remove-level-btn {
    width: 34px;
    height: 34px;
  }

  .level-input {
    min-height: 40px;
    font-size: 14px;
  }

  .level-input::placeholder {
    color: var(--muted);
  }

  .countdown {
    font-size: 68px;
  }

  h1 {
    font-size: 25px;
  }
}
