:root {
  --paper: #f7f0e1;
  --paper2: #efe4cd;
  --ink: #4a3b2c;
  --ink-soft: #7a6650;
  --accent: #c0703a;
  --accent-soft: #f1d2b4;
  --shadow: 0 6px 20px rgba(60, 40, 20, 0.22);
  --radius: 14px;
  font-size: 15px;
}
body.large { font-size: 21px; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #9fd0ea; color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Noto Serif", serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
button { font: inherit; color: inherit; cursor: pointer; }

#loading { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; background: var(--paper); z-index: 50; transition: opacity 0.6s; }
#loading.gone { opacity: 0; pointer-events: none; }
.ltitle { font-size: 2.2em; letter-spacing: 0.02em; }
.lsub { color: var(--ink-soft); margin-top: 0.4em; font-style: italic; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hud-top { position: absolute; top: 0.8em; left: 0.8em; right: 0.8em; display: flex; align-items: center; gap: 0.8em; pointer-events: none; }
#hud-top > * { pointer-events: auto; }
.title { background: var(--paper); padding: 0.35em 0.9em; border-radius: 999px; box-shadow: var(--shadow); font-size: 1.05em; }
#clock { background: rgba(247, 240, 225, 0.85); padding: 0.35em 0.8em; border-radius: 999px; box-shadow: var(--shadow); font-variant-numeric: tabular-nums; min-width: 6.5em; text-align: center; }
.topbtns { margin-left: auto; display: flex; gap: 0.45em; }
.topbtns button, #camctl button { width: 2.4em; height: 2.4em; border-radius: 50%; border: none; background: var(--paper); box-shadow: var(--shadow); font-size: 1.05em; }
.topbtns button:hover, #camctl button:hover { background: var(--accent-soft); }

#camctl { position: absolute; right: 0.8em; top: 50%; transform: translateY(-50%); display: grid; grid-template-columns: 1fr 1fr; gap: 0.4em; pointer-events: none; }
#camctl button { pointer-events: auto; opacity: 0.85; }
body.pad #camctl { display: none; }

#bottom { position: absolute; left: 0; right: 0; bottom: 0.8em; display: flex; flex-direction: column; align-items: center; gap: 0.55em; pointer-events: none; }
#bottom > * { pointer-events: auto; }
#toolbar { display: flex; gap: 0.35em; background: var(--paper); padding: 0.35em; border-radius: 999px; box-shadow: var(--shadow); }
.tool { position: relative; display: flex; flex-direction: column; align-items: center; gap: 0.1em; border: none; background: transparent; border-radius: 999px; padding: 0.45em 0.95em 0.35em; color: var(--ink-soft); font-size: 0.92em; }
.tool .icon { width: 1.6em; height: 1.6em; }
.tool kbd { position: absolute; top: 0.15em; right: 0.55em; font-size: 0.65em; font-family: inherit; color: var(--ink-soft); opacity: 0.6; }
body.pad .tool kbd, body.touch .tool kbd { display: none; }
.tool:hover { background: var(--paper2); }
.tool.on { background: var(--accent); color: #fffaf2; }
.icon { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

#variants { display: none; background: rgba(247, 240, 225, 0.95); border-radius: var(--radius); box-shadow: var(--shadow); padding: 0.45em 0.6em 0.6em; max-width: min(96vw, 62em); }
#variants.show { display: block; }
.vlabel { font-size: 0.85em; color: var(--ink-soft); margin: 0 0.2em 0.35em; display: flex; justify-content: space-between; gap: 1em; }
.vrow { display: flex; gap: 0.5em; overflow-x: auto; padding: 0.15em; }
.card { position: relative; flex: 0 0 auto; width: 7.2em; border: 2px solid transparent; background: var(--paper2); border-radius: 12px; padding: 0.3em 0.3em 0.35em; display: flex; flex-direction: column; align-items: center; }
.card img { width: 6.4em; height: 6.4em; border-radius: 8px; display: block; background: #f1e6cf; }
.card .vname { font-size: 0.78em; margin-top: 0.25em; text-align: center; line-height: 1.15; }
.card.on { border-color: var(--accent); background: #fff8ec; }
.card .star { position: absolute; top: 0.2em; right: 0.35em; font-size: 1.05em; color: rgba(74, 59, 44, 0.25); }
.card .star:hover { color: var(--accent); }
.card .star.fav { color: #e2a325; text-shadow: 0 0 4px rgba(255, 255, 255, 0.9); }

#hint { display: none; background: rgba(74, 59, 44, 0.78); color: #fff8ec; padding: 0.4em 1em; border-radius: 999px; font-size: 0.9em; text-align: center; max-width: 94vw; }
#hint.show { display: block; }
#drawctl, #selpanel, #turnctl { display: none; gap: 0.5em; align-items: center; background: var(--paper); padding: 0.4em 0.5em; border-radius: 999px; box-shadow: var(--shadow); }
#drawctl.show, #selpanel.show, #turnctl.show { display: flex; }
#turnctl button { border: none; background: var(--paper2); border-radius: 999px; padding: 0.45em 1em; }
#turnctl button:hover { background: var(--accent-soft); }
#sel-title { padding: 0 0.6em; font-style: italic; }
.selbtns { display: flex; gap: 0.35em; }
#selpanel.line .itemonly { display: none; }
#drawctl button, .selbtns button, .wide { border: none; background: var(--paper2); border-radius: 999px; padding: 0.45em 1em; }
#drawctl button:hover, .selbtns button:hover, .wide:hover { background: var(--accent-soft); }
#draw-finish, #sel-done { background: var(--accent); color: #fffaf2; }
#draw-finish:disabled { opacity: 0.45; cursor: default; }
#sel-remove { color: #9a3b2a; }

#toasts { position: absolute; top: 4em; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 0.4em; align-items: center; pointer-events: none; }
.toast { background: var(--paper); box-shadow: var(--shadow); padding: 0.5em 1.1em; border-radius: 999px; opacity: 0; transform: translateY(-8px); transition: all 0.4s; }
.toast.show { opacity: 1; transform: none; }

#radial { display: none; position: absolute; inset: 0; background: rgba(40, 30, 20, 0.25); }
#radial.show { display: block; }
.ritem { position: absolute; transform: translate(-50%, -50%); width: 6.2em; height: 6.2em; border-radius: 50%; background: var(--paper); box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.2em; color: var(--ink-soft); transition: transform 0.12s; }
.ritem .icon { width: 2em; height: 2em; }
.ritem.on { background: var(--accent); color: #fffaf2; transform: translate(-50%, -50%) scale(1.12); }
.rhint { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(74, 59, 44, 0.8); color: #fff8ec; padding: 0.4em 0.9em; border-radius: 999px; font-size: 0.85em; }

#panels { display: none; position: absolute; inset: 0; background: rgba(40, 30, 20, 0.35); place-items: center; }
#panels.show { display: grid; }
.panel { display: none; flex-direction: column; background: var(--paper); border-radius: 18px; box-shadow: var(--shadow); width: min(92vw, 34em); max-height: 86vh; padding: 1.1em 1.3em 1.2em; }
.panel.show { display: flex; }
.panel h2 { margin: 0 0 0.5em; font-weight: normal; font-size: 1.5em; }
.panel h3 { margin: 1.1em 0 0.4em; font-weight: normal; font-size: 1.1em; color: var(--accent); }
.pbody { overflow-y: auto; }
.pbody p { line-height: 1.45; margin: 0 0 0.7em; }
.small { color: var(--ink-soft); font-size: 0.9em; }
.pfoot { margin-top: 0.8em; color: var(--ink-soft); font-size: 0.85em; text-align: center; }
.panel table { border-collapse: collapse; width: 100%; font-size: 0.92em; }
.panel td { padding: 0.28em 0.4em; border-bottom: 1px solid var(--paper2); vertical-align: top; }
.panel td:first-child { white-space: nowrap; color: var(--ink-soft); width: 45%; }
.wide { width: 100%; margin-top: 0.6em; padding: 0.6em 1em; background: var(--accent); color: #fffaf2; font-size: 1.05em; }
.wide.danger { background: var(--paper2); color: #9a3b2a; }
#tries { list-style: none; padding: 0; margin: 0; }
#tries li { padding: 0.25em 0; }
#tries li em { display: block; margin-left: 1.6em; color: var(--ink-soft); font-size: 0.88em; }
#tries .tick { display: inline-block; width: 1.6em; color: var(--accent); }
#tries li.done { color: var(--ink-soft); }

.srow { display: flex; align-items: center; justify-content: space-between; gap: 1em; padding: 0.4em 0.6em; border-radius: 10px; }
.srow.focus { background: var(--paper2); }
body:not(.pad) .srow.focus { background: transparent; }
.srow.sbutton { display: block; padding: 0.1em 0.6em; }
.sctl { display: flex; align-items: center; gap: 0.4em; }
.sval { min-width: 7.5em; text-align: center; }
.step { width: 2em; height: 2em; border-radius: 50%; border: none; background: var(--paper2); font-size: 1.2em; line-height: 1; }
.step:hover { background: var(--accent-soft); }

.glyph { display: inline-grid; place-items: center; min-width: 1.6em; height: 1.6em; padding: 0 0.3em; border-radius: 999px; background: #3c332b; color: #fff; font-family: system-ui, sans-serif; font-size: 0.75em; font-weight: 600; vertical-align: middle; }
.g-a { background: #3d8a4f; } .g-b { background: #b8433a; } .g-x { background: #3b6fb0; } .g-y { background: #c99a25; }
body.styling #variants { display: none; }
#stylepanel { display: none; position: absolute; left: 0.8em; top: 4.2em; width: min(23.5em, 44vw); max-height: calc(100vh - 5em); flex-direction: column; background: rgba(247, 240, 225, 0.97); border-radius: 18px; box-shadow: var(--shadow); padding: 0.9em 1em 1em; }
#stylepanel.show { display: flex; }
#stylepanel h2 { margin: 0; font-weight: normal; font-size: 1.3em; }
#style-sub { color: var(--ink-soft); font-style: italic; font-size: 0.9em; margin: 0.1em 0 0.5em; }
.strow { padding: 0.3em 0.5em 0.4em; border-radius: 10px; }
body.pad .strow.focus { background: var(--paper2); }
.stlabel { font-size: 0.85em; color: var(--ink-soft); margin-bottom: 0.3em; }
.stopts { display: flex; flex-wrap: wrap; gap: 0.35em; }
.strow.inline { display: flex; align-items: center; justify-content: space-between; gap: 0.6em; }
.strow.inline .stlabel { margin: 0; }
.sw { width: 1.75em; height: 1.75em; border-radius: 50%; border: 2px solid rgba(74, 59, 44, 0.18); padding: 0; position: relative; }
.sw.orig::after { content: ''; position: absolute; left: 50%; top: 50%; width: 0.4em; height: 0.4em; margin: -0.2em; border-radius: 50%; background: rgba(255, 255, 255, 0.85); box-shadow: 0 0 0 1px rgba(74, 59, 44, 0.35); }
.sw.on, .chip.on { outline: 3px solid var(--accent); outline-offset: 2px; border-color: #fff; }
.chip { border: none; background: var(--paper2); border-radius: 999px; padding: 0.3em 0.8em; font-size: 0.9em; }
.chip:hover, .sw:hover { filter: brightness(1.06); }
.chip.on { background: #fff8ec; }
body.pad .strow.focus .pfocus { box-shadow: 0 0 0 3px #3c332b; }
.lookchip { display: inline-flex; align-items: center; gap: 0.15em; border: none; background: var(--paper2); border-radius: 999px; padding: 0.3em 0.35em 0.3em 0.55em; }
.lookchip i { display: block; width: 0.75em; height: 1.3em; border-radius: 3px; }
.lookchip .forget { margin-left: 0.25em; width: 1.3em; height: 1.3em; display: grid; place-items: center; border-radius: 50%; color: var(--ink-soft); font-style: normal; }
.lookchip .forget:hover { background: var(--accent-soft); }
.vstyle { border: none; background: var(--accent); color: #fffaf2; border-radius: 999px; padding: 0.15em 0.8em; font-size: 0.95em; margin-left: auto; }
.vstyle kbd { font-family: inherit; opacity: 0.7; font-size: 0.8em; margin-left: 0.3em; }
body.pad .vstyle kbd, body.touch .vstyle kbd { display: none; }
body.pad .pointeronly { display: none; }
.padonly { display: none; }
body.pad .padonly { display: inline; }
body.pad .pfoot.padonly { display: block; }
.vlabel .padonly { opacity: 0.85; }
