:root {
  --ink: #1e2925;
  --muted: #6d7772;
  --paper: #f4f1e8;
  --card: #fffdf7;
  --line: #d9d4c5;
  --green: #1f6653;
  --red: #b94d42;
  --shadow: 0 14px 40px rgb(34 49 42 / 9%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: radial-gradient(circle at 10% 0%, #fffdf7 0, transparent 32rem), var(--paper); }
button, input, select { font: inherit; }
button, select, input { border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
button { padding: .65rem .9rem; cursor: pointer; transition: .16s ease; }
button:hover:not(:disabled) { border-color: var(--green); transform: translateY(-1px); }
button:disabled { cursor: not-allowed; opacity: .45; }
button.primary { border-color: var(--green); background: var(--green); color: white; }
:focus-visible { outline: 3px solid #e4b44f; outline-offset: 2px; }
.topbar { position: sticky; z-index: 20; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 2rem; padding: 1rem clamp(1rem, 4vw, 3rem); border-bottom: 1px solid var(--line); background: rgb(244 241 232 / 92%); backdrop-filter: blur(16px); }
h1, h2, p { margin: 0; }
h1 { font-family: Georgia, serif; font-size: clamp(1.25rem, 2.2vw, 2rem); font-weight: 500; }
h2 { font-size: 1.1rem; }
.eyebrow, .section-label { color: var(--green); font-size: .69rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.toolbar { display: flex; flex-wrap: wrap; align-items: end; justify-content: end; gap: .6rem; }
.toolbar label { display: grid; gap: .25rem; color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; }
.toolbar input, .toolbar select { min-height: 38px; padding: .45rem .7rem; text-transform: none; }
main { width: min(1500px, 100%); margin: auto; padding: .8rem clamp(.75rem, 2.5vw, 2rem) 2rem; }
.character-grid {
  position: sticky;
  z-index: 15;
  top: 4.9rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: .3rem;
  max-height: 148px;
  overflow: auto;
  overscroll-behavior: contain;
  padding: .6rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgb(255 253 247 / 96%);
  box-shadow: 0 5px 20px rgb(34 49 42 / 7%);
}
.character-button { aspect-ratio: 1; min-width: 0; padding: 0; border-color: transparent; background: transparent; font-family: "Noto Serif SC", "Songti SC", SimSun, serif; font-size: 1.55rem; }
.character-button:hover { background: #e8efe9; }
.character-button.active { border-color: var(--green); background: var(--green); color: white; }
.workspace { margin-top: .8rem; min-width: 0; }
.empty-state { display: grid; place-items: center; min-height: 300px; color: var(--muted); }
.empty-state span { font-family: serif; font-size: 9rem; opacity: .1; }
.detail {
  display: grid;
  grid-template-columns: minmax(280px, .9fr) minmax(380px, 1.1fr);
  grid-template-areas: "glyph analysis" "export export";
  align-items: start;
  gap: .8rem;
  min-width: 0;
}
.glyph-card { grid-area: glyph; min-width: 0; }
.analysis-column {
  grid-area: analysis;
  display: flex;
  flex-direction: column;
  align-self: stretch;
  min-width: 0;
  min-height: 0;
  height: min(66vh, 600px);
  gap: .8rem;
}
.glyph-card, .decomposition-card, .strokes-card, .export-card { border: 1px solid var(--line); border-radius: 16px; background: var(--card); box-shadow: var(--shadow); }
.glyph-card, .decomposition-card, .export-card { padding: clamp(.8rem, 1.6vw, 1.2rem); }
.section-heading { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
#selected-character { font-family: "Noto Serif SC", SimSun, serif; font-size: 2rem; font-weight: 500; }
.code-point, .count-badge { padding: .3rem .5rem; border-radius: 999px; background: #e9e6dc; color: var(--muted); font-size: .7rem; font-family: ui-monospace, monospace; }

.svg-host {
  display: grid;
  place-items: center;
  width: min(100%, 380px, 38vh);
  aspect-ratio: 1;
  margin: .55rem auto;
  border-radius: 14px;
  background-color: #faf8f0;
  background-image: linear-gradient(#e4e0d5 1px, transparent 1px), linear-gradient(90deg, #e4e0d5 1px, transparent 1px);
  background-size: 12.5% 12.5%;
  overflow: hidden;
}
.svg-host svg { width: 88%; height: 88%; overflow: visible; }
.svg-host path[id] { fill: #171d1b; }
.svg-host path[clip-path] { fill: none; stroke: transparent; stroke-width: 128; stroke-linecap: round; stroke-linejoin: round; }
.svg-host .interactive-stroke { cursor: pointer; }
.svg-host .interactive-stroke:hover { stroke: #c14e42; }
.svg-host .interactive-stroke:focus { outline: none; stroke: #e4b44f; }
.svg-host .interactive-stroke.stroke-hidden { stroke: transparent; }
.hint, .loading, .error, .export-card p { color: var(--muted); font-size: .78rem; }
.loading, .error { grid-column: 1 / -1; }
.error { color: var(--red); }
.glyph-meta { display: grid; grid-template-columns: 1fr 1.5fr; gap: .45rem; }
.glyph-meta p { display: grid; gap: .15rem; padding: .5rem; border-radius: 9px; background: #f2efe6; }
.glyph-meta span { color: var(--muted); font-size: .62rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.glyph-meta strong { font-size: .78rem; font-weight: 600; }
.decomposition { margin: .7rem 0; }
.decomposition > div { display: grid; grid-template-columns: 6.3rem 1fr; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid #ece8dd; }
.decomposition dt { color: var(--muted); font-size: .7rem; }
.decomposition dd { margin: 0; font-family: "Noto Serif SC", SimSun, serif; font-size: 1rem; line-height: 1.3; overflow-wrap: anywhere; }
.decomposition code { font-size: .7rem; }
.decomposition-actions, .export-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.decomposition-actions button { padding: .45rem .65rem; }
.decomposition-card { flex: 0 1 auto; min-height: 0; max-height: min(28vh, 240px); overflow: auto; }
.strokes-card {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: auto;
  padding: .85rem 1rem;
}
.stroke-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(5.7rem, 1fr));
  align-content: start;
  flex: 1 1 auto;
  gap: .45rem;
  min-height: 0;
  margin-top: .65rem;
  padding: .15rem;
  overflow: auto;
  overscroll-behavior: contain;
}
.stroke-item { display: grid; grid-template-columns: auto 1.5rem 1fr; grid-template-rows: 1.45rem 2.6rem; align-items: center; min-width: 0; padding: .35rem; border: 1px solid var(--line); border-radius: 10px; background: #faf8f0; cursor: pointer; }
.stroke-item input { grid-row: 1; accent-color: var(--green); }
.stroke-number { color: var(--muted); font: 700 .75rem ui-monospace, monospace; }
.stroke-thumb { grid-column: 1 / -1; grid-row: 2; display: grid; place-items: center; min-width: 0; min-height: 0; overflow: hidden; }
.stroke-thumb svg { width: 100%; height: 100%; color: var(--ink); }
.stroke-label { display: none; }
.export-card { grid-area: export; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
footer { padding: 1rem 2rem 2rem; color: var(--muted); font-size: .75rem; text-align: center; }
@media (max-width: 1050px) {
  .detail {
    grid-template-columns: 1fr;
    grid-template-areas: "glyph" "analysis" "export";
  }
  .analysis-column { height: auto; }
  .decomposition-card { max-height: none; }
  .strokes-card { height: min(42vh, 340px); }
  .svg-host { width: min(100%, 390px, 48vh); }
}
@media (max-width: 800px) {
  .topbar { align-items: start; flex-direction: column; gap: .8rem; }
  .toolbar { justify-content: start; }
  .character-grid { position: static; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); max-height: 150px; }
  .export-card { align-items: start; flex-direction: column; }
}


/* Workspace layout: keep the character list above and expose analysis beside the main glyph. */
.detail {
  grid-template-columns: minmax(260px, minmax(0, .82fr)) minmax(360px, minmax(0, 1.18fr));
  grid-template-areas: "glyph analysis" "export export";
}
.analysis-column {
  align-self: stretch;
  height: min(66vh, 600px);
}
.decomposition-card {
  flex: 0 1 auto;
  max-height: min(32vh, 280px);
}
.strokes-card {
  flex: 1 1 0;
  height: auto;
}
@media (max-width: 1050px) {
  .detail {
    grid-template-columns: 1fr;
    grid-template-areas: "glyph" "analysis" "export";
  }
  .analysis-column { height: auto; }
  .decomposition-card { max-height: none; }
  .strokes-card { height: min(42vh, 340px); }
}

.workspace { margin-top: .8rem; }
.empty-state { display: grid; place-items: center; min-height: 300px; color: var(--muted); }
.empty-state span { font-family: serif; font-size: 9rem; opacity: .1; }
.detail {
  display: grid;
  grid-template-columns: minmax(280px, .9fr) minmax(360px, 1.1fr);
  align-items: start;
  gap: .8rem;
  min-width: 0;
}
.analysis-column {
  display: flex;
  flex-direction: column;
  align-self: start;
  min-width: 0;
  min-height: 0;
  gap: .8rem;
}
.glyph-card, .decomposition-card, .strokes-card, .export-card { border: 1px solid var(--line); border-radius: 16px; background: var(--card); box-shadow: var(--shadow); }
.glyph-card, .decomposition-card, .export-card { padding: clamp(.8rem, 1.6vw, 1.2rem); }
.section-heading { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
#selected-character { font-family: "Noto Serif SC", SimSun, serif; font-size: 2rem; font-weight: 500; }
.code-point, .count-badge { padding: .3rem .5rem; border-radius: 999px; background: #e9e6dc; color: var(--muted); font-size: .7rem; font-family: ui-monospace, monospace; }

.svg-host {
  display: grid;
  place-items: center;
  width: min(100%, 380px, 38vh);
  aspect-ratio: 1;
  margin: .55rem auto;
  border-radius: 14px;
  background-color: #faf8f0;
  background-image: linear-gradient(#e4e0d5 1px, transparent 1px), linear-gradient(90deg, #e4e0d5 1px, transparent 1px);
  background-size: 12.5% 12.5%;
  overflow: hidden;
}
.svg-host svg { width: 88%; height: 88%; overflow: visible; }
.svg-host path[id] { fill: #171d1b; }
.svg-host path[clip-path] { fill: none; stroke: transparent; stroke-width: 128; stroke-linecap: round; stroke-linejoin: round; }
.svg-host .interactive-stroke { cursor: pointer; }
.svg-host .interactive-stroke:hover { stroke: #c14e42; }
.svg-host .interactive-stroke:focus { outline: none; stroke: #e4b44f; }
.svg-host .interactive-stroke.stroke-hidden { stroke: transparent; }
.hint, .loading, .error, .export-card p { color: var(--muted); font-size: .78rem; }
.loading, .error { grid-column: 1 / -1; }
.error { color: var(--red); }
.glyph-meta { display: grid; grid-template-columns: 1fr 1.5fr; gap: .45rem; }
.glyph-meta p { display: grid; gap: .15rem; padding: .5rem; border-radius: 9px; background: #f2efe6; }
.glyph-meta span { color: var(--muted); font-size: .62rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.glyph-meta strong { font-size: .78rem; font-weight: 600; }
.decomposition { margin: .7rem 0; }
.decomposition > div { display: grid; grid-template-columns: 6.3rem 1fr; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid #ece8dd; }
.decomposition dt { color: var(--muted); font-size: .7rem; }
.decomposition dd { margin: 0; font-family: "Noto Serif SC", SimSun, serif; font-size: 1rem; line-height: 1.3; overflow-wrap: anywhere; }
.decomposition code { font-size: .7rem; }
.decomposition-actions, .export-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.decomposition-actions button { padding: .45rem .65rem; }
.decomposition-card { max-height: min(32vh, 280px); overflow: auto; }
.strokes-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: min(38vh, 340px);
  padding: .85rem 1rem;
}
.stroke-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(5.7rem, 1fr));
  align-content: start;
  flex: 1 1 auto;
  gap: .45rem;
  min-height: 0;
  margin-top: .65rem;
  padding: .15rem;
  overflow: auto;
  overscroll-behavior: contain;
}
.stroke-item { display: grid; grid-template-columns: auto 1.5rem 1fr; grid-template-rows: 1.45rem 2.6rem; align-items: center; min-width: 0; padding: .35rem; border: 1px solid var(--line); border-radius: 10px; background: #faf8f0; cursor: pointer; }
.stroke-item input { grid-row: 1; accent-color: var(--green); }
.stroke-number { color: var(--muted); font: 700 .75rem ui-monospace, monospace; }
.stroke-thumb { grid-column: 1 / -1; grid-row: 2; display: grid; place-items: center; min-width: 0; min-height: 0; overflow: hidden; }
.stroke-thumb svg { width: 100%; height: 100%; color: var(--ink); }
.stroke-label { display: none; }
.export-card { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
footer { padding: 1rem 2rem 2rem; color: var(--muted); font-size: .75rem; text-align: center; }
@media (max-width: 1050px) {
  .detail { grid-template-columns: 1fr; }
  .svg-host { width: min(100%, 390px, 48vh); }
}
@media (max-width: 800px) {
  .topbar { align-items: start; flex-direction: column; gap: .8rem; }
  .toolbar { justify-content: start; }
  .character-grid { position: static; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); max-height: 150px; }
  .export-card { align-items: start; flex-direction: column; }
}


/* Final viewport layout: keep the picker visible and place analysis beside the glyph. */
@media (min-width: 1051px) {
  .character-grid {
    top: 5.25rem;
    max-height: 132px;
  }
  .detail {
    display: grid;
    grid-template-columns: minmax(270px, .76fr) minmax(500px, 1.24fr);
    grid-template-areas: "glyph analysis" "export export";
    align-items: stretch;
    gap: .8rem;
  }
  .svg-host {
    width: min(100%, 300px, 34vh);
  }
  .analysis-column {
    display: flex;
    flex-direction: column;
    align-self: stretch;
    min-width: 0;
    min-height: 0;
    height: min(56vh, 520px);
    gap: .8rem;
  }
  .decomposition-card {
    flex: 0 0 auto;
    max-height: min(28vh, 220px);
    overflow: auto;
  }
  .strokes-card {
    flex: 1 1 0;
    min-height: 0;
    height: auto;
    overflow: hidden;
  }
}
@media (max-width: 1050px) {
  .detail {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas: "glyph" "analysis" "export";
  }
  .analysis-column { height: auto; }
  .decomposition-card { max-height: none; }
  .strokes-card { height: min(42vh, 340px); }
  .svg-host { width: min(100%, 360px, 42vh); }
}

