:root {
  color-scheme: light;
  --ink: #191919;
  --muted: #595959;
  --line: #dddddf;
  --yellow: #fee500;
  --pale: #fff8c5;
  font: 100%/1.55 system-ui, -apple-system, "Malgun Gothic", sans-serif;
  color: var(--ink);
  background: #f4f4f4;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input { font: inherit; color: inherit; }
button, summary { cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible { outline: 2px solid #655900; outline-offset: 3px; }
.shell { max-width: 38rem; margin: auto; background: white; min-height: 100dvh; }
header { min-height: 3.75rem; padding: .5rem 1.4rem; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #ededee; font-weight: 800; font-size: 1.25rem; }
main { padding: 0 clamp(1rem, 5vw, 1.5rem); }
h1 { margin: 1.55rem 0 1.25rem; font-size: clamp(1.9rem, 7vw, 2.45rem); line-height: 1.21; letter-spacing: -.045em; overflow-wrap: anywhere; }
h2 { margin: 0 0 .4rem; font-size: 1.2rem; letter-spacing: -.02em; }
p { margin: 0; }
form { min-height: calc(100dvh - 3.75rem); display: flex; flex-direction: column; }
.field { display: grid; gap: .2rem; border: 1px solid var(--line); border-radius: 1rem; padding: .7rem .95rem; margin-bottom: .8rem; font-size: .875rem; color: var(--muted); }
.field:focus-within { border-color: #887900; }
.field input { background: white; border: 0; padding: 0; width: 100%; min-width: 0; min-height: 1.85rem; font-size: 1.25rem; font-weight: 700; color: var(--ink); }
fieldset { margin: .25rem 0 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; color: var(--muted); font-size: .875rem; margin-bottom: .4rem; }
.choices { display: flex; gap: .65rem; }
.choices label { display: flex; flex: 1; justify-content: space-between; align-items: center; padding: .75rem .85rem; border: 1px solid var(--line); border-radius: .9rem; min-height: 3.05rem; font-weight: 700; cursor: pointer; }
.choices label:has(:checked) { background: var(--pale); border-color: #a58e00; }
.choices input { accent-color: #564900; width: 1.15rem; height: 1.15rem; }
.action { padding: 1.35rem 0 max(1.25rem, env(safe-area-inset-bottom)); margin-top: auto; }
.primary { width: 100%; border: 0; border-radius: .9rem; min-height: 3.4rem; background: var(--yellow); color: #111; font-weight: 800; font-size: 1.12rem; }
.primary:disabled { opacity: .7; }
.message { margin-top: .75rem; color: #952d15; }
.quiet { background: none; border: none; text-decoration: underline; font-size: .875rem; padding: .65rem .35rem; }
.metadata, .source { color: var(--muted); font-size: .875rem; margin-bottom: .75rem; }
#result { padding-bottom: 1.5rem; }
#result h1 { margin-bottom: .35rem; }
.chart { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); grid-template-rows: repeat(4, minmax(3.3rem,auto)); gap: 1px; background: #aaa; border: 1px solid #aaa; border-radius: .85rem; overflow: hidden; }
.chart button, .center { background: white; border: 0; min-width: 0; padding: .35rem .15rem; text-align: center; }
.chart button { font-weight: 700; font-size: .875rem; }
.chart button[aria-pressed="true"] { background: var(--pale); }
.chart button:focus-visible { outline-offset: -3px; }
.chart button span { display: block; font-size: .75rem; color: var(--muted); font-weight: 400; }
.center { grid-area: 2 / 2 / 4 / 4; display: grid; place-content: center; gap: .2rem; font-size: 1.3rem; font-weight: 800; }
.center small { font-size: .875rem; color: var(--muted); font-weight: 500; }
.palace-info, .summary { padding: .8rem .9rem; border: 1px solid var(--line); border-radius: .85rem; margin-top: .75rem; overflow-wrap: anywhere; }
.reading-text { overflow-wrap: anywhere; line-height: 1.75; }
.reading-text > * + * { margin-top: .8rem; }
.reading-text p { white-space: pre-line; }
.reading-text h3 { margin-bottom: .25rem; font-size: 1rem; line-height: 1.45; }
.reading-text ul, .reading-text ol { padding-inline-start: 1.45rem; margin-bottom: 0; }
.reading-text li + li { margin-top: .25rem; }
.palace-info p { color: var(--muted); font-size: .875rem; }
.readings { margin-top: 1.35rem; }
.topic { border: 1px solid var(--line); border-radius: .8rem; margin: .5rem 0; overflow: hidden; }
summary { padding: .7rem .85rem; font-weight: 650; }
.topic[open] > summary { background: var(--pale); }
.topic.translated { border-color: #d8bf47; background: #fffbea; }
.topic.translated > summary { background: #fff5c6; }
.translation-badge { margin-inline-start: .55rem; font-size: .8rem; color: #594a12; font-weight: 600; }

.topic-body { padding: .8rem .85rem; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.75; }
.original { margin-top: .6rem; }
.original summary { padding-left: 0; text-decoration: underline; font-size: .875rem; color: var(--muted); }
.source { margin-top: .9rem; }
.source a { color: inherit; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.chat-launch {
  position: fixed;
  z-index: 4;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  min-height: 3rem;
  padding: .65rem 1.2rem;
  border: 1px solid #ddc600;
  border-radius: 1.5rem;
  background: var(--yellow);
  color: #191919;
  font-weight: 750;
  box-shadow: 0 .2rem .75rem #28210026;
}
.chat-panel {
  position: fixed;
  z-index: 5;
  right: max(.75rem, env(safe-area-inset-right));
  bottom: max(.75rem, env(safe-area-inset-bottom));
  width: min(27rem, calc(100vw - 1.5rem));
  height: min(36rem, 66dvh);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  border: 1px solid #d9cc92;
  border-radius: 1.15rem;
  background: rgb(255 249 223 / 91%);
  backdrop-filter: blur(3px);
  box-shadow: 0 .6rem 2rem #2a200533;
  overflow: hidden;
}
.chat-header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .55rem .8rem; border-bottom: 1px solid #e8ddb0; }
.chat-header h2 { margin: 0; font-size: 1rem; }
.chat-close { min-height: 2.5rem; border: 0; border-radius: .55rem; padding: .35rem .65rem; background: #fff; font-size: .875rem; }
.chat-history { overflow-y: auto; overscroll-behavior: contain; padding: .7rem; scrollbar-gutter: stable; }
.chat-bubble { width: fit-content; max-width: 92%; margin-bottom: .6rem; padding: .55rem .72rem; border-radius: .8rem; overflow-wrap: anywhere; }
.chat-answer { background: white; border-top-left-radius: .25rem; }
.chat-question { margin-left: auto; background: var(--yellow); border-top-right-radius: .25rem; white-space: pre-wrap; }
.chat-period { font-size: .8rem; color: var(--muted); margin-bottom: .35rem; }
.chat-form { display: flex; flex-direction: row; gap: .5rem; min-height: 0; padding: .55rem .7rem; margin: 0; border-top: 1px solid #e8ddb0; }
.chat-form input { width: 100%; min-width: 0; background: white; border: 1px solid #d9d0b3; border-radius: .7rem; padding: .55rem .65rem; }
.chat-form button { flex: none; border: 0; border-radius: .7rem; background: var(--yellow); padding: .55rem .75rem; font-weight: 700; }
.chat-form button:disabled { opacity: .65; }
.chat-status { padding: 0 .75rem .5rem; color: var(--muted); font-size: .85rem; }
@media (min-width: 56rem) { .chat-panel { right: 1rem; height: min(42rem, 82dvh); } }

.page-jump {
  position: fixed;
  z-index: 4;
  display: grid;
  gap: .4rem;
  right: max(1rem, env(safe-area-inset-right));
  bottom: calc(max(1rem, env(safe-area-inset-bottom)) + 3.6rem);
}
.page-jump button {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: .8rem;
  background: white;
  color: var(--ink);
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 .15rem .5rem #28210020;
}
.page-jump button:hover { background: var(--pale); }
.page-jump.chat-is-open { visibility: hidden; }
@media (min-width: 56rem) {
  .page-jump {
    right: calc((100vw - 38rem) / 2 - 3.5rem);
    bottom: 1rem;
  }
}
