:root {
  color-scheme: light;
  --ink: #1d2928;
  --muted: #5a6967;
  --paper: #f4f1e9;
  --panel: #fffefa;
  --line: #d8ded6;
  --accent: #176b63;
  --accent-dark: #10534d;
  --accent-soft: #e3f0eb;
  --warning: #8e4e1e;
  --shadow: 0 12px 32px rgb(29 41 40 / 7%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans TC", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--paper);
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.topbar {
  min-height: 68px;
  padding: 12px max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  color: var(--ink);
  font-size: 20px;
  font-weight: 760;
  letter-spacing: 0.04em;
  text-decoration: none;
}

.topbar-actions,
.font-tools,
.reader-toolbar,
.reader-navigation {
  display: flex;
  align-items: center;
  gap: 8px;
}

.font-tools span {
  color: var(--muted);
  font-size: 14px;
}

.page-shell {
  width: min(100% - 32px, 980px);
  margin: 0 auto;
  padding: 28px 0 max(40px, env(safe-area-inset-bottom));
}

.panel,
.card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-panel {
  width: min(100%, 460px);
  margin: min(12vh, 100px) auto 0;
  padding: clamp(22px, 5vw, 38px);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(28px, 5vw, 36px);
  line-height: 1.2;
}

h2 {
  margin-bottom: 6px;
  font-size: 21px;
  line-height: 1.35;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 760;
  letter-spacing: 0.09em;
}

.muted {
  color: var(--muted);
  line-height: 1.6;
}

.login-form,
.score-fields {
  display: grid;
  gap: 16px;
}

.login-form {
  margin-top: 26px;
}

.login-form label,
.comment-field > span {
  font-weight: 700;
}

.login-form input,
.comment-field textarea {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 1px solid #aebbb5;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 18px;
}

.comment-field textarea {
  min-height: 104px;
  resize: vertical;
  line-height: 1.55;
}

.button {
  min-height: 46px;
  padding: 10px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 720;
  text-decoration: none;
  touch-action: manipulation;
}

.button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid #86c4b2;
  outline-offset: 2px;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.button-primary {
  background: var(--accent);
  color: #fff;
}

.button-primary:hover:not(:disabled) {
  background: var(--accent-dark);
}

.button-primary:disabled {
  background: #8b9993;
  cursor: not-allowed;
}

.button-quiet {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
}

.button-quiet:hover {
  background: var(--accent-soft);
}

.page-heading {
  margin: 20px 0 24px;
}

.page-heading .muted {
  margin-bottom: 0;
}

.card-list {
  display: grid;
  gap: 12px;
}

.card {
  width: 100%;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--ink);
  text-align: left;
}

button.card {
  cursor: pointer;
}

button.card:hover {
  border-color: #8bb9ac;
  background: #fbfffc;
}

.card-title {
  display: block;
  margin-bottom: 5px;
  font-size: 19px;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.card-detail {
  display: block;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.card-mark {
  min-width: 44px;
  color: var(--accent-dark);
  font-size: 25px;
  font-weight: 750;
  text-align: right;
}

.back-button {
  margin-bottom: 8px;
}

.reveal-panel {
  margin-top: 22px;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.reveal-panel p {
  margin-bottom: 0;
}

.reader-toolbar {
  justify-content: space-between;
  flex-wrap: wrap;
}

.reader-navigation {
  margin-left: auto;
}

.reader-heading {
  margin-top: 20px;
}

.manuscript {
  max-height: min(58vh, 680px);
  margin-bottom: 20px;
  padding: clamp(18px, 4vw, 32px);
  overflow: auto;
  font-size: var(--reading-font-size, 20px);
  line-height: 1.95;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.score-panel {
  padding: clamp(18px, 4vw, 28px);
  display: grid;
  gap: 22px;
}

.score-fields {
  gap: 18px;
}

.score-group {
  margin: 0;
  padding: 0;
  border: 0;
}

.score-group legend {
  margin-bottom: 10px;
  font-weight: 740;
}

.rating-options {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.rating-choice {
  min-height: 48px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #aebbb5;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
}

.rating-choice input {
  width: 1px;
  height: 1px;
  position: absolute;
  opacity: 0;
}

.rating-choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.rating-choice:has(input:focus-visible) {
  outline: 3px solid #86c4b2;
  outline-offset: 2px;
}

.comment-field {
  display: grid;
  gap: 9px;
}

.save-button {
  width: 100%;
  min-height: 54px;
  font-size: 18px;
}

.ranking-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
  list-style: none;
  counter-reset: rank;
}

.ranking-card {
  padding: 18px;
}

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

.ranking-name {
  margin: 0;
  font-size: 19px;
  overflow-wrap: anywhere;
}

.ranking-score {
  color: var(--accent-dark);
  font-size: 22px;
  font-weight: 800;
  white-space: nowrap;
}

.ranking-meta,
.notice {
  color: var(--muted);
  line-height: 1.6;
}

.notice {
  padding: 12px 15px;
  border: 1px solid #b8d6c9;
  border-radius: 10px;
  background: var(--accent-soft);
}

.notice.is-error {
  border-color: #dfbca1;
  background: #fff4e9;
  color: var(--warning);
}

.empty-state {
  padding: 22px;
  border: 1px dashed #aebbb5;
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

@media (max-width: 560px) {
  .topbar {
    min-height: 60px;
    padding: 8px 12px;
  }

  .brand {
    font-size: 18px;
  }

  .topbar-actions,
  .font-tools {
    gap: 5px;
  }

  .font-tools span {
    display: none;
  }

  .page-shell {
    width: calc(100% - 24px);
    padding-top: 18px;
  }

  .page-heading {
    margin: 15px 0 18px;
  }

  .card {
    padding: 16px;
  }

  .reveal-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .reveal-panel .button {
    width: 100%;
  }

  .reader-toolbar {
    gap: 6px;
  }

  .reader-toolbar > .muted {
    order: 3;
    width: 100%;
    margin: 0;
  }

  .reader-navigation .button {
    min-height: 42px;
    padding: 8px 10px;
  }

  .manuscript {
    max-height: 52vh;
    border-radius: 13px;
    line-height: 1.85;
  }

  .ranking-head {
    align-items: flex-start;
  }
}

[hidden] {
  display: none;
}
