:root {
  --bg: #0b0716; --panel: #150d27; --line: #2e2050; --text: #efe6d2; --muted: #a99bc4;
  --gold: #e6c46e; --gold-d: #9c7a2e; --violet: #8a6cff;
  --serif: Palatino, "Palatino Linotype", "Book Antiqua", Georgia, serif;
  color-scheme: dark;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, sans-serif; }
body { min-height: 100dvh; padding-top: env(safe-area-inset-top); }
button { white-space: nowrap; font: inherit; color: var(--text); background: #221640; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: linear-gradient(135deg, #e6c46e, #b8893a); color: #1a1028; border: 0; font-weight: 700; }
button.ghost { background: transparent; }
button.wide { width: 100%; margin-top: 10px; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; }
.top h1 { font: 700 22px var(--serif); color: var(--gold); margin: 0; letter-spacing: .06em; }
.top button { padding: 6px 12px; font-size: 14px; }

.layout { display: flex; flex-direction: column; }
.stage { position: relative; height: 58dvh; min-height: 340px; touch-action: manipulation; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hint { position: absolute; left: 0; right: 0; bottom: 10px; text-align: center; font: italic 15px var(--serif); color: var(--muted); pointer-events: none; transition: opacity .4s; }
.focus-close { position: absolute; top: 10px; right: 12px; width: 40px; height: 40px; border-radius: 50%; padding: 0; background: #0009; }

.panel { padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); }
.seg { display: flex; background: #120a22; border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 10px; padding: 9px 6px; font-size: 15px; color: var(--muted); }
.seg button.on { background: #2b1c52; color: var(--gold); }
.question { width: 100%; margin-top: 10px; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: #120a22; color: var(--text); font: 16px var(--serif); }
.actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.actions .primary { flex: 1; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }

.reading { margin-top: 14px; display: grid; gap: 12px; }
.pos { display: grid; grid-template-columns: 64px 1fr; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 12px; animation: rise .5s ease both; }
.pos img { width: 64px; border-radius: 6px; box-shadow: 0 4px 14px #0008; cursor: zoom-in; }
.pos img.rev { transform: rotate(180deg); }
.pos .ph { width: 64px; height: 110px; border: 2px dashed var(--gold-d); border-radius: 6px; opacity: .5; }
.pos h3 { margin: 0; font: 700 13px system-ui; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); display: flex; justify-content: space-between; align-items: center; }
.pos h3 button { font-size: 12px; padding: 3px 8px; letter-spacing: 0; text-transform: none; font-weight: 500; }
.pos h4 { margin: 2px 0 4px; font: 700 18px var(--serif); }
.pos h4 small { color: var(--violet); font: italic 14px var(--serif); }
.pos p { margin: 4px 0 0; color: #d9cfe9; font-size: 15px; }
.kw { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
.kw span { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #2b1c52; color: #d8c8ff; }
.muted { color: var(--muted); font-style: italic; }
.summary { background: linear-gradient(160deg, #2a1748, #150d27); border: 1px solid var(--gold-d); border-radius: 16px; padding: 14px; animation: rise .6s ease both; }
.summary h3 { margin: 0 0 6px; font: 700 18px var(--serif); color: var(--gold); }
.summary p { margin: 6px 0; font-size: 15px; color: #e3d9f2; }
.summary .q { font: italic 16px var(--serif); color: var(--gold); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

dialog { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 18px; padding: 0; width: min(680px, 100vw - 16px); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: #000a; backdrop-filter: blur(4px); }
dialog[open] { display: flex; flex-direction: column; }
.pk-head { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.pk-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pk-slots button { padding: 6px; text-align: left; font-size: 12px; line-height: 1.25; min-height: 52px; }
.pk-slots button b { display: block; color: var(--gold); letter-spacing: .1em; font-size: 11px; text-transform: uppercase; }
.pk-slots button.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.pk-tools { display: flex; gap: 8px; }
.pk-tools input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: #120a22; color: var(--text); font-size: 16px; }
.orient { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.orient button { border: 0; border-radius: 0; padding: 8px 10px; font-size: 13px; background: transparent; color: var(--muted); }
.orient button.on { background: #2b1c52; color: var(--gold); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips button { padding: 5px 11px; font-size: 13px; border-radius: 99px; white-space: nowrap; color: var(--muted); }
.chips button.on { color: #1a1028; background: var(--gold); border-color: var(--gold); }
.pk-grid { overflow-y: auto; padding: 10px 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; flex: 1; }
.pk-card { padding: 4px; border-radius: 10px; background: #150d27; text-align: center; font-size: 11.5px; line-height: 1.2; }
.pk-card img { width: 100%; border-radius: 6px; display: block; margin-bottom: 4px; aspect-ratio: 512/880; background: #221640; }
.pk-card.used { opacity: .3; }
.pk-card.sel { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.pk-foot { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.pk-foot .primary { flex: 1; }

.jr-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.jr-head h2 { margin: 0; font: 700 20px var(--serif); color: var(--gold); }
#jrList { overflow-y: auto; padding: 12px 16px; display: grid; gap: 10px; }
.jr-item { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.jr-item time { color: var(--muted); font-size: 12px; }
.jr-item .q { font: italic 15px var(--serif); color: var(--gold); }

@media (min-width: 900px) and (min-aspect-ratio: 4/3) {
  .layout { flex-direction: row; height: calc(100dvh - 52px); }
  .stage { flex: 1.5; height: auto; }
  .panel { flex: 1; max-width: 480px; overflow-y: auto; }
}
