:root {
  color-scheme: dark;
  --bg: #020808;
  --panel: rgba(4, 25, 30, 0.82);
  --panel-strong: rgba(6, 37, 45, 0.94);
  --line: rgba(0, 204, 255, 0.34);
  --line-hot: #00d9ff;
  --text: #e8f7f8;
  --muted: #88aeb8;
  --green: #55ff9d;
  --violet: #aa7cff;
  --pink: #ff75f4;
  --orange: #ff9a6d;
  --yellow: #ffd84e;
  --danger: #ff4f5f;
  font-family:
    Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui,
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 10%, rgba(0, 216, 255, 0.12), transparent 28rem),
    radial-gradient(circle at 82% 22%, rgba(255, 117, 244, 0.1), transparent 24rem),
    linear-gradient(135deg, #020808 0%, #031216 52%, #05070d 100%);
  color: var(--text);
}

body::after {
  position: fixed;
  inset: 0;
  z-index: 999;
  pointer-events: none;
  content: "";
  opacity: 0;
  background:
    radial-gradient(circle at center, rgba(85, 255, 157, 0.38), transparent 34rem),
    linear-gradient(90deg, rgba(0, 217, 255, 0.2), rgba(255, 216, 78, 0.16));
}

body.countdown-ready::after {
  animation: ready-flash 1.05s ease-out;
}

body.countdown-ready #countdown {
  color: var(--green);
  text-shadow: 0 0 18px rgba(85, 255, 157, 0.9);
}

body.countdown-ready .hack-summary {
  animation: ready-panel 1.05s ease-out;
}

@keyframes ready-flash {
  0% {
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes ready-panel {
  0%,
  100% {
    box-shadow: none;
  }
  18% {
    box-shadow: 0 0 34px rgba(85, 255, 157, 0.36);
  }
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image: linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px);
  background-size: 100% 4px;
  mask-image: linear-gradient(transparent, black 18%, black 82%, transparent);
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 0 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--line-hot);
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 4.5rem);
  line-height: 0.96;
}

h1 span {
  display: inline-block;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  color: var(--green);
  background: rgba(3, 20, 24, 0.8);
  white-space: nowrap;
}

.pulse {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 14px var(--green);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 22px 0;
  padding: 8px;
  border: 1px solid rgba(0, 217, 255, 0.26);
  background: rgba(0, 10, 14, 0.64);
}

.tab-button {
  position: relative;
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  border: 1px solid rgba(0, 217, 255, 0.22);
  padding: 10px 12px;
  color: var(--muted);
  background: rgba(3, 18, 22, 0.86);
  text-align: left;
}

.tab-button.active {
  color: var(--text);
  background: linear-gradient(90deg, rgba(0, 217, 255, 0.22), rgba(170, 124, 255, 0.18));
  border-color: var(--line-hot);
  box-shadow:
    inset 0 -3px 0 var(--line-hot),
    0 0 18px rgba(0, 217, 255, 0.14);
}

.tab-button strong,
.tab-button small {
  display: block;
}

.tab-button strong {
  font-size: 1rem;
  color: currentColor;
}

.tab-button small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.75rem;
}

.tab-button.active small {
  color: rgba(232, 247, 248, 0.72);
}

.tab-icon {
  display: grid;
  width: 38px;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid rgba(0, 217, 255, 0.32);
  color: var(--line-hot);
  background: rgba(0, 0, 0, 0.24);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
}

.tab-button.active .tab-icon {
  color: var(--bg);
  background: var(--green);
  border-color: var(--green);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
}

.tool-grid {
  grid-template-columns: minmax(320px, 0.9fr) minmax(360px, 1.1fr);
  gap: 18px;
}

.control-panel,
.readout-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    0 0 30px rgba(0, 217, 255, 0.08);
}

.control-panel {
  padding: 18px;
}

.readout-panel {
  padding: 18px;
  background: var(--panel-strong);
}

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

h2 {
  font-size: 1.15rem;
}

.panel-code {
  color: var(--orange);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

fieldset {
  min-width: 0;
  margin: 0 0 18px;
  padding: 14px;
  border: 1px solid rgba(0, 217, 255, 0.24);
}

legend,
label span {
  color: var(--muted);
  font-size: 0.86rem;
}

label {
  display: grid;
  gap: 8px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(0, 217, 255, 0.35);
  border-radius: 0;
  padding: 0 12px;
  color: var(--text);
  background: rgba(2, 9, 11, 0.82);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--line-hot);
  box-shadow: 0 0 0 2px rgba(0, 217, 255, 0.16);
}

.field-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mod-slots {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-row button,
.counter button {
  min-height: 38px;
  border: 1px solid rgba(0, 217, 255, 0.38);
  color: var(--text);
  background: rgba(16, 42, 61, 0.85);
}

.quick-row button {
  min-width: 70px;
  padding: 0 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.segmented label {
  display: block;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid rgba(0, 217, 255, 0.32);
  color: var(--muted);
  background: rgba(2, 9, 11, 0.76);
}

.segmented input:checked + span {
  color: var(--text);
  border-color: var(--line-hot);
  background: rgba(0, 217, 255, 0.16);
}

.counter-grid {
  display: grid;
  gap: 10px;
}

.counter {
  display: grid;
  grid-template-columns: 1fr 38px 42px 38px;
  align-items: center;
  gap: 8px;
}

.counter-name {
  color: var(--text);
}

.counter-name small {
  display: block;
  color: var(--muted);
}

.counter output {
  display: grid;
  min-height: 38px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--yellow);
  background: rgba(0, 0, 0, 0.22);
}

.meter {
  display: grid;
  place-items: center;
  min-height: 260px;
}

.meter-ring {
  width: min(240px, 72vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(3, 18, 22, 1) 0 58%, transparent 59%),
    conic-gradient(var(--green) var(--fill, 0%), rgba(0, 217, 255, 0.1) 0);
  box-shadow: 0 0 34px rgba(85, 255, 157, 0.14);
}

.meter-ring strong {
  font-size: 3.1rem;
  line-height: 1;
}

.meter-ring span {
  color: var(--muted);
}

.readout-list,
.hack-summary {
  display: grid;
  gap: 10px;
}

.readout-list div,
.hack-summary div,
.cmu-result,
.combo-item,
.cmu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid rgba(0, 217, 255, 0.2);
  background: rgba(0, 0, 0, 0.18);
}

.readout-list span,
.hack-summary span,
.cmu-result span,
.combo-item span,
.cmu-row span {
  color: var(--muted);
}

.readout-list strong,
.hack-summary strong,
.cmu-result strong,
.combo-item strong,
.cmu-row strong {
  color: var(--yellow);
  text-align: right;
}

.timeline {
  display: grid;
  gap: 8px;
  max-height: 410px;
  margin-top: 16px;
  overflow: auto;
  overflow-anchor: none;
  padding-right: 4px;
}

.timeline.hack-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-height: 330px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  border-left: 2px solid rgba(0, 217, 255, 0.5);
  background: rgba(0, 0, 0, 0.2);
}

.timeline.hack-grid .timeline-item {
  grid-template-columns: auto 1fr auto;
  min-height: 38px;
  padding: 7px 9px;
}

.timeline-item.done {
  opacity: 0.52;
}

.timeline-item.next {
  border-left-color: var(--green);
  box-shadow: inset 0 0 0 1px rgba(85, 255, 157, 0.2);
}

.timeline-item.burnout {
  grid-column: 1 / -1;
  border-left-color: var(--danger);
}

.timeline-item b {
  color: var(--line-hot);
}

.timeline-item strong {
  color: var(--text);
}

.timeline-item span {
  color: var(--muted);
}

.cmu-table,
.combo-list {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.cmu-result {
  display: grid;
  align-items: start;
  justify-content: stretch;
}

.cmu-result strong {
  font-size: 2.4rem;
  text-align: left;
}

.cmu-result p {
  color: var(--muted);
}

.cmu-result.compact strong {
  font-size: 1.55rem;
}

@media (max-width: 820px) {
  .app-shell {
    width: calc(100vw - 16px);
    max-width: 620px;
    padding-top: 12px;
  }

  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
    gap: 14px;
    padding-bottom: 14px;
  }

  .eyebrow {
    margin-bottom: 6px;
    font-size: 0.72rem;
  }

  h1 {
    font-size: clamp(2.1rem, 12vw, 3rem);
    line-height: 1.04;
  }

  h1 span {
    display: block;
  }

  .status-pill {
    justify-self: start;
    min-height: 34px;
    padding: 0 11px;
    font-size: 0.9rem;
  }

  .tabs {
    position: sticky;
    top: 0;
    z-index: 10;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin: 14px -2px 16px;
    padding: 6px;
    width: calc(100% + 4px);
    max-width: calc(100% + 4px);
    background: rgba(0, 11, 14, 0.92);
    backdrop-filter: blur(14px);
    overflow: hidden;
  }

  .tab-button {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 7px;
    min-width: 0;
    min-height: 82px;
    padding: 9px 6px 8px;
    text-align: center;
  }

  .tab-button strong {
    font-size: 0.92rem;
  }

  .tab-button small {
    margin-top: 2px;
    font-size: 0.68rem;
  }

  .tab-button > span:not(.tab-icon) {
    min-width: 0;
    max-width: 100%;
  }

  .tab-icon {
    width: 32px;
    font-size: 0.74rem;
  }

  .tool-grid,
  .field-grid.two,
  .mod-slots {
    grid-template-columns: 1fr;
  }

  .tool-grid {
    gap: 12px;
  }

  .control-panel,
  .readout-panel {
    padding: 12px;
  }

  .panel-heading {
    margin-bottom: 14px;
  }

  fieldset {
    margin-bottom: 14px;
    padding: 12px;
  }

  input,
  select {
    min-height: 48px;
  }

  .quick-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .quick-row button {
    min-width: 0;
    padding: 0 8px;
  }

  #cmu .quick-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .meter {
    min-height: 190px;
  }

  .meter-ring {
    width: min(178px, 58vw);
  }

  .meter-ring strong {
    font-size: 2.45rem;
  }

  .readout-list div,
  .hack-summary div,
  .cmu-result,
  .combo-item,
  .cmu-row {
    min-height: 44px;
    padding: 9px 10px;
  }

  .cmu-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .cmu-row strong {
    text-align: left;
    font-size: 1.05rem;
  }

  .cmu-result strong {
    font-size: 2.05rem;
  }

  .cmu-result.compact strong {
    font-size: 1.45rem;
  }

  .segmented {
    grid-template-columns: 1fr;
  }

  .timeline-item {
    grid-template-columns: 42px 1fr auto;
  }

  .timeline.hack-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: 300px;
  }

  .timeline.hack-grid .timeline-item {
    grid-template-columns: 30px 1fr auto;
    gap: 6px;
  }

  .timeline.hack-grid .timeline-item span {
    grid-column: auto;
    justify-self: end;
    font-size: 0.78rem;
  }

  .timeline.hack-grid .timeline-item strong {
    text-align: right;
  }

  .timeline-item span {
    grid-column: auto;
  }
}
