:root {
  color-scheme: light;
  --ink: #1c1915;
  --muted: #6b645c;
  --line: #e4ddd4;
  --paper: #f7f3ec;
  --card: #fffdf9;
  --accent: #0f6e56;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Iowan Old Style", Palatino, "Songti SC", serif;
  background: var(--paper);
  color: var(--ink);
}
.level-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: #10261f;
  color: #f4f1ea;
}
.level-main { min-width: 0; flex: 1; }
.level-kicker { font-size: 12px; letter-spacing: .08em; opacity: .7; font-family: sans-serif; }
.level-code { font-size: 28px; font-weight: 650; }
.units { font-family: sans-serif; font-size: 15px; margin-top: 2px; }
.level-links { display: flex; flex-wrap: wrap; gap: 8px; }
.level-more { display: none; }
.level-bar { position: relative; }
.web-btn, button, .types button {
  font-family: sans-serif;
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.web-btn { background: #d7f5ea; color: #0d3b2e; text-decoration: none; }
.gen-dock { display: none; }
.pop-backdrop { display: none; }
main { max-width: 760px; margin: 0 auto; padding: 28px 20px 80px; }
.card, #article {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
}
h1, h2 { font-weight: 650; margin: 0 0 12px; }
.hint { margin: 0 0 14px; color: var(--muted); font-family: sans-serif; font-size: 14px; }
.picker-label {
  font-family: sans-serif;
  font-size: 13px;
  color: var(--muted);
  margin: 4px 0 8px;
}
.optional { opacity: .75; }
.types { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.types button { background: #efeae2; color: var(--ink); }
.types button.on { background: var(--accent); color: white; }
.scene-wrap { margin-bottom: 4px; }
.types.scenes button { background: #e7f0eb; }
.types.scenes button.on { background: #0d5a46; color: white; }
input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font: inherit;
  margin-bottom: 12px;
}
#generate, .actions button { background: var(--accent); color: white; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.status, .meta { color: var(--muted); font-family: sans-serif; font-size: 14px; }
.history { margin-top: 18px; }
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.history-head h2 { margin: 0; font-size: 20px; }
.ghost {
  background: #efeae2;
  color: var(--ink);
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.history-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  padding: 12px 0;
  color: inherit;
  font: inherit;
}
.history-item:hover { color: var(--accent); }
.history-title { font-size: 16px; font-weight: 600; }
.history-meta { font-family: sans-serif; font-size: 13px; color: var(--muted); }
.tok {
  font: inherit;
  background: transparent;
  border: 0;
  border-bottom: 1px dashed #b7c9c1;
  padding: 0;
  border-radius: 0;
  color: inherit;
  cursor: pointer;
}
.tok.phrase { background: #e7f6ef; }
p.para { line-height: 1.75; font-size: 18px; }
.zh { color: #3d4f48; font-size: 15px; }
.pop {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: min(360px, calc(100% - 32px));
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 12px 40px rgba(40, 30, 10, .12);
  font-family: sans-serif;
  z-index: 20;
}
.block { margin-top: 16px; }
.item { padding: 8px 0; border-top: 1px solid var(--line); font-family: sans-serif; font-size: 14px; }

@media (max-width: 720px) {
  body {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
  .level-bar {
    position: sticky;
    align-items: flex-start;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 12px;
  }
  .level-code { font-size: 22px; }
  .units { font-size: 13px; opacity: .9; }
  .level-more {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0 12px;
    background: rgba(215, 245, 234, 0.16);
    color: #d7f5ea;
    font-size: 13px;
    font-weight: 700;
  }
  .level-links {
    display: none;
    position: absolute;
    top: calc(100% - 4px);
    right: 12px;
    flex-direction: column;
    padding: 10px;
    border-radius: 14px;
    background: #16352c;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  }
  body.menu-open .level-links { display: flex; }
  main { padding: 18px 14px 28px; }
  .card, #article {
    border-radius: 14px;
    padding: 16px;
  }
  h1 { font-size: 1.35rem; }
  .types {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding-bottom: 4px;
    margin-bottom: 12px;
  }
  .types button {
    flex: none;
    scroll-snap-align: start;
    min-height: 40px;
    white-space: nowrap;
  }
  #setup #generate { display: none; }
  .gen-dock {
    display: block;
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    z-index: 15;
  }
  #generate-dock {
    width: 100%;
    min-height: 48px;
    background: var(--accent);
    color: white;
    font-size: 16px;
    font-weight: 700;
    box-shadow: 0 10px 28px rgba(15, 110, 86, 0.28);
  }
  #generate-dock:disabled { opacity: 0.55; }
  p.para { font-size: 17px; line-height: 1.8; }
  .zh { font-size: 14px; line-height: 1.55; }
  .pop-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 18;
    background: rgba(28, 25, 21, 0.35);
  }
  .pop-backdrop[hidden] { display: none; }
  .pop {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: min(70vh, 520px);
    overflow: auto;
    border-radius: 18px 18px 0 0;
    border: 0;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -12px 40px rgba(40, 30, 10, 0.16);
  }
}
