:root {
  --bg: #12171e;
  --panel: #1a212c;
  --panel-2: #222b38;
  --line: #314052;
  --text: #e8eef5;
  --muted: #93a4b8;
  --gold: #e2b15c;
  --gold-dim: rgba(226, 177, 92, 0.16);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}

h1, h2, h3, p { margin: 0; }

h1 {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.kicker {
  color: var(--gold);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 3px;
}

.models {
  display: flex;
  flex-wrap: nowrap;
  gap: 14px;
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.2;
}

.models a {
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.models a[aria-current="page"] {
  color: var(--gold);
  font-weight: 600;
}

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

button, input {
  font: inherit;
  color: inherit;
}

.tools button, .term {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}

.tools button[aria-pressed="true"] {
  background: var(--gold-dim);
  border-color: var(--gold);
  color: var(--gold);
}

#shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 320px;
  min-height: 0;
}

#list, #detail {
  min-height: 0;
  overflow: auto;
  background: var(--panel);
}

#list { border-right: 1px solid var(--line); padding: 14px; }
#detail { border-left: 1px solid var(--line); padding: 18px 18px 28px; }

.search { display: grid; gap: 6px; margin-bottom: 14px; }
.search span { color: var(--muted); font-size: 12px; }
.search input {
  width: 100%;
  background: #10151c;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.group { margin-bottom: 16px; }
.group h2 {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 8px 0;
}

.term {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  border-radius: 8px;
  margin-bottom: 4px;
  padding: 7px 10px;
}

.term .en { font-weight: 600; }
.term .zh { color: var(--muted); font-size: 12px; }
.term[aria-current="true"] {
  border-color: var(--gold);
  background: var(--gold-dim);
  animation: term-flash 2.4s ease-in-out infinite;
}

@keyframes term-flash {
  0%, 100% { background: rgba(226, 177, 92, 0.1); }
  50% { background: rgba(226, 177, 92, 0.48); }
}

@media (prefers-reduced-motion: reduce) {
  .term[aria-current="true"] { animation: none; }
}

#stage { position: relative; min-height: 0; background: #8ea4b8; }
#c { width: 100%; height: 100%; display: block; touch-action: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.label {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -120%);
  background: rgba(16, 21, 28, 0.82);
  border: 1px solid rgba(232, 238, 245, 0.25);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  max-width: calc(100% - 24px);
  color: #10202c;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  pointer-events: none;
}

.hint-touch { display: none; }

#sheet-scrim, #mobile-nav { display: none; }

#d-en {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 28px;
  line-height: 1.15;
  margin: 4px 0 6px;
}

#d-zh { color: var(--gold); margin-bottom: 16px; }

#detail h3 {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 0 6px;
}

#d-def, #d-note, #d-model {
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 14px;
}

#d-model-wrap { color: #d5deea; }
.source { margin-top: 18px; color: var(--muted); font-size: 12px; line-height: 1.4; }

@media (max-width: 860px) {
  html, body { height: 100dvh; }

  header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  }

  h1 { font-size: 18px; }
  .kicker { letter-spacing: 0.08em; }
  .models { margin-top: 2px; font-size: 13px; }

  .tools {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
  }

  .tools button {
    min-height: 40px;
    padding: 8px 4px;
    font-size: 13px;
  }

  #shell { display: block; position: relative; }

  #stage {
    position: absolute;
    inset: 0 0 calc(58px + env(safe-area-inset-bottom)) 0;
  }

  .hint-desktop { display: none; }
  .hint-touch {
    display: block;
    top: 8px;
    bottom: auto;
    font-size: 11px;
  }

  #sheet-scrim {
    display: block;
    position: absolute;
    inset: 0 0 calc(58px + env(safe-area-inset-bottom)) 0;
    z-index: 3;
    border: 0;
    padding: 0;
    background: rgba(8, 12, 18, 0.4);
    opacity: 0;
    pointer-events: none;
  }

  body.show-list #sheet-scrim,
  body.show-detail #sheet-scrim {
    opacity: 1;
    pointer-events: auto;
  }

  #list, #detail {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(58px + env(safe-area-inset-bottom));
    z-index: 4;
    height: min(68dvh, 560px);
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    transform: translateY(110%);
    transition: transform 0.28s ease;
    box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.35);
  }

  body.show-list #list,
  body.show-detail #detail { transform: translateY(0); }

  #mobile-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: var(--panel);
    border-top: 1px solid var(--line);
  }

  #mobile-nav button {
    min-height: 42px;
    border-radius: 12px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    padding: 6px 8px;
  }

  #mobile-nav button[aria-expanded="true"] {
    border-color: var(--gold);
    color: var(--gold);
    background: var(--gold-dim);
  }

  #open-detail {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.15;
  }

  #detail-name {
    color: var(--gold);
    font-size: 11px;
  }

  #detail-name:empty { display: none; }

  #d-en { font-size: 24px; }
}

@media (max-width: 860px) and (max-height: 500px) {
  header { flex-direction: row; align-items: center; }
  .tools { grid-template-columns: auto auto auto; }
  .tools button { padding: 6px 8px; }
  #list, #detail { height: min(74dvh, 300px); }
}

@media (prefers-reduced-motion: reduce) {
  #list, #detail { transition: none; }
}
