:root {
  --ink: #1a2a26;
  --ink-soft: #4d655c;
  --bg: #eef4f1;
  --panel: #f7fbf9;
  --panel-2: #ffffff;
  --wine: #245c4f;
  --wine-deep: #163d34;
  --wine-soft: rgba(36, 92, 79, 0.12);
  --line: rgba(36, 92, 79, 0.22);
  --cyan: #245c4f;
  --cyan-deep: #163d34;
  --gold: #8a6230;
  --ok: #2e7d4f;
  --warn: #c4922a;
  --hot: #c45c2a;
  --danger: #7b3fb8;
  --shadow: 0 16px 36px rgba(22, 61, 52, 0.1);
  --radius: 20px;
  --header-h: 4.25rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Noto Sans TC", "PingFang HK", "Microsoft JhengHei", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: 18px;
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(36, 92, 79, 0.12), transparent 42%),
    radial-gradient(circle at 92% 8%, rgba(196, 163, 90, 0.12), transparent 40%),
    linear-gradient(180deg, #f7fbf9 0%, var(--bg) 46%, #e2eee8 100%);
  line-height: 1.65;
  overflow-x: clip;
}

#main {
  flex: 1 0 auto;
}

img {
  max-width: 100%;
  display: block;
}

button,
input,
select {
  font-family: inherit;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 200;
  padding: 0.5rem 0.85rem;
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
}

.skip-link:focus {
  top: calc(var(--safe-top) + 0.6rem);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: var(--header-h);
  padding: calc(0.55rem + var(--safe-top)) 11.5rem 0.55rem 1rem;
  background: rgba(247, 251, 249, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand img {
  width: 40px;
  height: 40px;
  border-radius: 12px;
}

.brand-text strong {
  display: block;
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.3;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 0 0 auto;
}

.btn-reset {
  border: 2px solid var(--wine);
  background: #fff;
  color: var(--wine);
  font-weight: 800;
  font-size: 0.9rem;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  min-height: 44px;
  box-shadow: 0 4px 0 var(--wine-deep);
  transform: translateY(-1px);
}

.btn-reset:hover {
  background: var(--wine-soft);
}

.btn-reset:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 var(--wine-deep);
}

.layout {
  width: min(1100px, calc(100% - 1.5rem));
  margin: 0 auto;
  padding: 1.1rem 0 calc(2rem + var(--safe-bottom));
}

.hero {
  text-align: center;
  margin-bottom: 1rem;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2.1rem);
  font-weight: 900;
  color: var(--wine);
}

.hero .lead {
  margin: 0.45rem 0 0;
  color: var(--ink-soft);
  font-size: 1.05rem;
}

.tablist-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.25rem 1rem;
  padding: 0.15rem 0.25rem 0.35rem;
  max-width: 100%;
}

.tablist {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  min-width: min-content;
}

.tab {
  flex: 0 0 auto;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  font-weight: 800;
  font-size: 0.95rem;
  padding: 0.55rem 1.05rem;
  border-radius: 14px;
  cursor: pointer;
  min-height: 46px;
  white-space: nowrap;
  box-shadow: 0 3px 0 rgba(36, 92, 79, 0.12);
  transition: transform 0.15s var(--ease), box-shadow 0.15s, background 0.15s, color 0.15s;
}

.tab:hover {
  transform: translateY(-2px);
  border-color: var(--wine);
  color: var(--wine);
}

.tab[aria-selected="true"] {
  background: linear-gradient(180deg, #3d8f78, var(--wine-deep));
  color: #fff;
  border-color: var(--wine-deep);
  box-shadow: 0 5px 0 #0e2822, 0 10px 18px rgba(22, 61, 52, 0.22);
}

.tab[data-tab="recap"][aria-selected="true"] {
  background: linear-gradient(180deg, #c4a35a, #8a6230);
  border-color: #6a4a22;
  box-shadow: 0 5px 0 #6a4a22, 0 10px 18px rgba(138, 98, 48, 0.22);
}

.panel {
  display: none;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.15rem 1.4rem;
  min-width: 0;
}

.panel.is-active {
  display: block;
}

.panel[hidden] {
  display: none !important;
}

.panel h2 {
  margin: 0;
  text-align: center;
  font-size: 1.35rem;
  color: var(--cyan);
}

.principle {
  margin: 0.65rem auto 1rem;
  max-width: 42rem;
  text-align: center;
  color: var(--ink-soft);
}

.principle strong {
  color: var(--gold);
}

.lab-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.scope-stage,
.control-panel,
.info-card {
  min-width: 0;
}

.mag-line {
  margin: 0 0 0.55rem;
  text-align: center;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--wine-deep);
}

.eyepiece {
  width: min(88vw, 480px, 100%);
  margin: 0 auto;
}

.eyepiece svg {
  display: block;
  width: 100%;
  height: auto;
}

.control-panel {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.9rem;
}

.panel-title,
.info-card > h3 {
  margin: 0 0 0.7rem;
  font-size: 1rem;
  color: var(--gold);
}

.step-card {
  background: #f4faf7;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.75rem 0.8rem 0.85rem;
  margin-bottom: 0.7rem;
}

.step-card h3 {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 0.55rem;
  font-size: 1rem;
  color: var(--ink);
}

.step-num {
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #3d8f78, var(--wine-deep));
  color: #fff;
  font-size: 0.85rem;
  font-weight: 900;
  flex: 0 0 auto;
}

.light-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 7.2rem;
  min-height: 44px;
  padding: 0.4rem 1rem;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(36, 92, 79, 0.16);
}

.light-switch.is-on {
  background: #fff8d6;
  border-color: #e0b45a;
  box-shadow: 0 0 0 3px rgba(255, 214, 80, 0.35), 0 3px 0 #c4922a;
}

.lamp {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #9aa8a2;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.12);
}

.light-switch.is-on .lamp {
  background: #ffe56a;
  box-shadow: 0 0 10px 4px rgba(255, 214, 80, 0.95);
}

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

.chip {
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  padding: 0.5rem 0.85rem;
  border-radius: 14px;
  cursor: pointer;
  min-height: 44px;
  box-shadow: 0 3px 0 rgba(36, 92, 79, 0.16);
  transform: translateY(-1px);
  transition: transform 0.12s var(--ease), box-shadow 0.12s, background 0.15s, color 0.15s, border-color 0.15s;
}

.chip:hover {
  transform: translateY(-3px);
  border-color: var(--wine);
  color: var(--wine);
}

.chip:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 transparent;
}

.chip.is-on {
  background: linear-gradient(180deg, #3d8f78, var(--wine-deep));
  color: #fff;
  border-color: var(--wine-deep);
  box-shadow: 0 4px 0 #0e2822, 0 8px 14px rgba(22, 61, 52, 0.22);
}

.chip.is-on:hover {
  color: #fff;
}

.objective-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.objective-row .chip-row {
  flex: 1 1 auto;
}

.nosepiece {
  width: 68px;
  height: 68px;
  position: relative;
  flex: 0 0 68px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #e7f2ee 0 18%, #9db5ac 19% 62%, #245c4f 63% 100%);
  transition: transform 0.45s var(--ease);
}

.nosepiece[data-obj="10"] {
  transform: rotate(120deg);
}

.nosepiece[data-obj="40"] {
  transform: rotate(240deg);
}

.nosepiece span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 24px;
  margin-left: -4px;
  margin-top: -26px;
  background: #163d34;
  border-radius: 4px;
  transform-origin: 4px 26px;
}

.nosepiece span::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -7px;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  border-radius: 50%;
  background: #245c4f;
  box-shadow: inset 0 0 0 2px #c4a35a;
}

.nosepiece span:nth-child(1) { transform: rotate(0deg); }
.nosepiece span:nth-child(2) { transform: rotate(120deg); }
.nosepiece span:nth-child(3) { transform: rotate(240deg); }

.slider-row label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  margin-bottom: 0.45rem;
}

.focus-badge {
  flex: 0 0 auto;
  font-size: 0.82rem;
  font-weight: 800;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: rgba(36, 48, 56, 0.08);
  color: var(--ink-soft);
}

.focus-badge.is-near {
  background: #f4e2b8;
  color: #6a4a16;
}

.focus-badge.is-sharp {
  background: var(--ok);
  color: #fff;
}

.slider-row input[type="range"] {
  --fill: 18%;
  width: 100%;
  height: 44px;
  border-radius: 999px;
  background: transparent;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  margin: 0;
}

.slider-row input[type="range"]:focus-visible {
  box-shadow: none;
}

.slider-row input[type="range"]::-webkit-slider-runnable-track {
  height: 18px;
  border-radius: 999px;
  background:
    linear-gradient(
      90deg,
      #3d8f78 0%,
      var(--wine) var(--fill),
      #d5e4de var(--fill),
      #d5e4de 100%
    );
  box-shadow: inset 0 2px 5px rgba(22, 61, 52, 0.18);
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 44px;
  height: 44px;
  margin-top: -13px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #5eae96, var(--wine-deep));
  cursor: grab;
  border: 3px solid #fff;
  box-shadow: 0 3px 0 var(--wine-deep), 0 7px 14px rgba(22, 61, 52, 0.3);
}

.slider-row input[type="range"]:active::-webkit-slider-thumb {
  cursor: grabbing;
  transform: scale(0.96);
}

.slider-row input[type="range"]::-moz-range-track {
  height: 18px;
  border-radius: 999px;
  background: #d5e4de;
  box-shadow: inset 0 2px 5px rgba(22, 61, 52, 0.18);
}

.slider-row input[type="range"]::-moz-range-progress {
  height: 18px;
  border-radius: 999px;
  background: linear-gradient(90deg, #3d8f78, var(--wine));
}

.slider-row input[type="range"]::-moz-range-thumb {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #5eae96, var(--wine-deep));
  cursor: grab;
  border: 3px solid #fff;
  box-shadow: 0 3px 0 var(--wine-deep), 0 7px 14px rgba(22, 61, 52, 0.3);
}

.task-box {
  margin-top: 0.2rem;
  padding: 0.8rem 0.9rem;
  border-radius: 14px;
  background: rgba(36, 92, 79, 0.08);
  border: 1px dashed rgba(36, 92, 79, 0.35);
  font-weight: 700;
  min-height: 3.2em;
}

.info-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.9rem;
}

.info-locked {
  margin: 0;
  padding: 0.9rem 0.7rem;
  text-align: center;
  color: var(--ink-soft);
  font-weight: 800;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #f4faf7;
}

.info-layout {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
}

.info-main {
  flex: 1 1 auto;
  min-width: 0;
}

.info-title {
  margin: 0 0 0.35rem;
  font-size: 1.12rem;
  font-weight: 900;
  color: var(--wine-deep);
}

.info-desc,
.tip-box p,
.science-note {
  margin: 0;
}

.tip-box {
  margin-top: 0.75rem;
  padding: 0.75rem 0.85rem;
  border-radius: 14px;
  background: rgba(36, 92, 79, 0.08);
}

.tip-box h4 {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
  color: var(--wine);
}

.science-note {
  margin-top: 0.7rem;
  color: #6d756f;
  font-size: 0.92rem;
}

.schematic {
  flex: 0 0 148px;
  margin: 0;
  padding: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f6f1e6;
}

.schematic svg {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.schematic figcaption {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  line-height: 1.45;
  color: #6d756f;
}

.record-progress {
  margin: 0 0 0.8rem;
  text-align: center;
  font-weight: 900;
  font-size: 1.15rem;
  color: var(--wine-deep);
}

.record-export {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  justify-content: center;
  margin: 0 0 0.45rem;
}

.name-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: min(100%, 16rem);
  font-weight: 800;
  text-align: left;
}

.name-field input {
  min-height: 44px;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  background: #fff;
}

.btn-export {
  border: 0;
  background: linear-gradient(180deg, #3d8f78, var(--wine-deep));
  color: #fff;
  font-weight: 900;
  font-size: 0.95rem;
  padding: 0.55rem 1.45rem;
  white-space: nowrap;
  border-radius: 999px;
  cursor: pointer;
  min-height: 44px;
  box-shadow: 0 4px 0 #0e2822;
}

.btn-export:hover {
  filter: brightness(1.06);
}

.btn-export:disabled {
  cursor: wait;
  filter: grayscale(0.2);
}

.export-status {
  min-height: 1.5em;
  margin: 0 0 0.85rem;
  text-align: center;
  font-weight: 700;
  color: var(--wine-deep);
}

.export-status.is-error {
  color: #8a3418;
}

.record-wrap {
  overflow-x: auto;
  max-width: 100%;
}

.record-table {
  width: 100%;
  border-collapse: collapse;
}

.record-table th,
.record-table td {
  text-align: left;
  vertical-align: top;
  padding: 0.7rem 0.55rem;
  border-bottom: 1px solid var(--line);
}

.record-table th {
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.record-name {
  font-weight: 800;
}

.status-yes {
  color: var(--ok);
  font-weight: 800;
}

.status-no {
  color: var(--ink-soft);
}

.choice-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.choice {
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  text-align: left;
  padding: 0.45rem 0.7rem;
  border-radius: 12px;
  cursor: pointer;
  min-height: 44px;
}

.choice.is-correct {
  background: #e7f6ee;
  border-color: var(--ok);
  color: #1d5c38;
}

.choice.is-wrong {
  background: #fdece6;
  border-color: var(--hot);
  color: #8a3418;
}

.see-feedback {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.see-feedback.is-correct {
  color: #1d5c38;
}

.see-feedback.is-wrong {
  color: #8a3418;
}

.recap-list {
  display: grid;
  gap: 0.85rem;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: recap;
}

.recap-list li {
  counter-increment: recap;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.95rem 1rem 0.95rem 3.4rem;
  position: relative;
}

.recap-list li::before {
  content: counter(recap);
  position: absolute;
  left: 0.85rem;
  top: 0.95rem;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 900;
  background: linear-gradient(180deg, #3d8f78, var(--wine-deep));
  color: #fff;
}

.site-footer {
  padding: 1rem 1.2rem calc(1rem + var(--safe-bottom));
  text-align: center;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
}

.site-footer a {
  color: var(--cyan);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.chip:focus-visible,
.choice:focus-visible,
.light-switch:focus-visible,
.tab:focus-visible,
.btn-reset:focus-visible,
.btn-export:focus-visible,
.name-field input:focus-visible,
.slider-row input[type="range"]:focus-visible {
  outline: 3px solid rgba(36, 92, 79, 0.45);
  outline-offset: 2px;
}

@media (min-width: 900px) {
  .lab-grid {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  }

  .scope-stage {
    grid-column: 1;
    grid-row: 1;
  }

  .info-card {
    grid-column: 1;
    grid-row: 2;
  }

  .control-panel {
    grid-column: 2;
    grid-row: 1 / span 2;
  }
}

@media (max-width: 800px) {
  .site-header {
    padding-right: 11.5rem;
  }

  .brand-text strong {
    font-size: 0.82rem;
  }

  .info-layout {
    flex-direction: column;
  }

  .schematic {
    flex-basis: auto;
    width: min(180px, 100%);
  }
}

@media (max-width: 700px) {
  .record-table thead {
    display: none;
  }

  .record-table,
  .record-table tbody,
  .record-table tr,
  .record-table td {
    display: block;
    width: 100%;
  }

  .record-table tr {
    border: 1px solid var(--line);
    border-radius: 16px;
    margin-bottom: 0.75rem;
    padding: 0.35rem 0.35rem 0.7rem;
    background: #fff;
  }

  .record-table td {
    border: 0;
    padding: 0.35rem 0.55rem;
  }

  .record-table td::before {
    display: block;
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--ink-soft);
  }

  .record-table td:nth-child(1)::before { content: "樣本"; }
  .record-table td:nth-child(2)::before { content: "狀態"; }
  .record-table td:nth-child(3)::before { content: "最高清晰倍數"; }
  .record-table td:nth-child(4)::before { content: "我看到……"; }
}

@media (max-width: 640px) {
  .site-header {
    flex-wrap: wrap;
    padding-right: 1rem;
  }

  .brand {
    flex: 1 1 auto;
    max-width: calc(100% - 10.75rem);
  }

  .header-tools {
    flex: 1 1 100%;
  }
}

@media (max-width: 600px) {
  html {
    font-size: 16px;
  }

  .panel {
    padding: 1rem 0.8rem 1.15rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
