:root {
  --bg: #1c1f1a;
  --panel: #262a23;
  --panel-2: #30352c;
  --line: #3d4337;
  --ink: #ecead9;
  --muted: #a9ab97;
  --accent: #c9a54a;     /* brass */
  --accent-ink: #1c1f1a;
  --ok: #7fae5c;
  --no: #c7614c;
  --info: #6f9bbd;
  --paper: #efe6cc;
  --paper-ink: #2a2417;
  --paper-line: #b9a978;
  --radius: 12px;
  --tap: 52px;
  font-size: 17px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
body { display: flex; overflow: hidden; user-select: none; -webkit-user-select: none; }
input, textarea, select { user-select: text; -webkit-user-select: text; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 650; letter-spacing: .01em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: .3rem 0 .7rem; line-height: 1.45; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* Navigation rail */
.rail { width: 92px; flex: none; background: #151813; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: stretch; padding: 10px 6px; gap: 6px; }
.rail .logo { display: grid; place-items: center; height: 60px; margin-bottom: 6px; }
.rail .logo img { width: 46px; height: 46px; border-radius: 10px; }
.rail a { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 2px;
  border-radius: 10px; color: var(--muted); text-decoration: none; font-size: .78rem; }
.rail a .ico { font-size: 1.45rem; line-height: 1; }
.rail a.active { background: var(--panel-2); color: var(--ink); }
.rail .spacer { flex: 1; }

main#view { flex: 1; overflow: auto; padding: 20px 24px 40px; position: relative; }
main#view.full { padding: 0; overflow: hidden; display: flex; flex-direction: column; }

/* Buttons */
.btn { min-height: var(--tap); padding: 0 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; font-weight: 550; touch-action: manipulation; }
.btn:active { transform: translateY(1px); filter: brightness(1.1); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ok { background: var(--ok); color: #12180e; border-color: transparent; }
.btn.no { background: var(--no); color: #1d0f0b; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--no); border-color: #5c3a31; background: transparent; }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: .9rem; }
.btn.xl { min-height: 84px; font-size: 1.3rem; padding: 0 30px; border-radius: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* Panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.tag { display: inline-block; padding: 3px 9px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-size: .8rem; color: var(--muted); }
.tag.accent { color: var(--accent); border-color: #6a5a2c; }

/* Forms */
label.f { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); }
input[type=text], input[type=number], input[type=search], textarea, select {
  background: #171a15; color: var(--ink); border: 1px solid var(--line); border-radius: 9px;
  padding: 10px 12px; font: inherit; min-height: 46px; width: 100%; }
textarea { resize: vertical; min-height: 64px; line-height: 1.4; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Mode chooser */
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.mode { text-align: left; padding: 14px; display: flex; flex-direction: column; justify-content: flex-start; border-radius: 12px; border: 2px solid var(--line); background: var(--panel-2); cursor: pointer; min-height: 120px; }
.mode.sel { border-color: var(--accent); }
.mode[disabled] { opacity: .5; cursor: default; }
.mode .t { font-weight: 700; font-size: 1.1rem; display: flex; justify-content: space-between; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.cardgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.cardtile { background: var(--paper); color: var(--paper-ink); border-radius: 12px; padding: 12px 14px; cursor: pointer; min-height: 110px; display: flex; flex-direction: column; gap: 6px; border: 2px solid transparent; }
.cardtile .t { font-weight: 750; font-size: 1.05rem; display: flex; justify-content: space-between; gap: 6px; }
.cardtile .m { font-size: .8rem; color: #5d543a; }
.cardtile.warn { border-color: #c7614c; }

/* Solo card render */
.solo-card { background: var(--paper); color: var(--paper-ink); border-radius: 14px; padding: 16px 18px; box-shadow: 0 6px 24px rgba(0,0,0,.35); font-size: 1.02rem; }
.sc-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid var(--paper-line); padding-bottom: 6px; margin-bottom: 8px; }
.sc-title { font-weight: 800; font-size: 1.25rem; letter-spacing: .03em; text-transform: uppercase; }
.sc-init { font-weight: 800; background: var(--paper-ink); color: var(--paper); border-radius: 8px; padding: 2px 9px; }
.sc-meta { font-size: .78rem; color: #6a5f43; margin-bottom: 8px; }
.sc-always { border: 2px solid var(--paper-ink); border-radius: 8px; padding: 8px 10px; margin: 6px 0 10px; font-size: .95rem; }
.sc-lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.sc-lines .sc-lines { margin: 6px 0 0 26px; }
.sc-line { display: flex; gap: 10px; padding: 6px 8px; border-radius: 8px; line-height: 1.4; transition: background .2s, opacity .2s; }
.sc-line > .lbl { flex: none; font-weight: 800; min-width: 22px; }
.sc-line > .body { flex: 1; }
.sc-line .cond { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.sc-line .tb { font-style: italic; color: #5d543a; }
.sc-line .then { font-weight: 700; color: #6b4e12; white-space: nowrap; }
.sc-line.current { background: #ffe8a3; box-shadow: inset 4px 0 0 #b8860b; }
.sc-line.st-false, .sc-line.st-failed, .sc-line.st-nosub { opacity: .45; }
.sc-line.st-false > .body, .sc-line.st-failed > .body { text-decoration: line-through; text-decoration-color: #7a6c48; }
.sc-line.st-applied { background: #d6e8c3; }
.term { border-bottom: 2px dotted currentColor; cursor: help; }
.kw { font-weight: 800; cursor: help; }

/* Game */
.gamebar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: #20241d; flex-wrap: wrap; }
.gamebar .name { font-weight: 700; }
.gamebar select { width: auto; min-height: 42px; }
.playarea { display: flex; gap: 10px; padding: 12px 16px; overflow-x: auto; border-bottom: 1px solid var(--line); min-height: 112px; align-items: stretch; background: #1a1d17; }
.playarea .empty { color: var(--muted); align-self: center; }
.pa { flex: none; width: 132px; min-height: 86px; border-radius: 10px; background: var(--paper); color: var(--paper-ink); padding: 8px 10px; position: relative; cursor: pointer; border: 3px solid transparent; display: flex; flex-direction: column; gap: 2px; }
.pa .i { position: absolute; top: 6px; right: 8px; font-weight: 800; }
.pa .t { font-weight: 750; padding-right: 18px; line-height: 1.15; }
.pa .s { font-size: .85rem; }
.pa .flags { margin-top: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.pa .flags span { font-size: .68rem; background: var(--paper-ink); color: var(--paper); border-radius: 4px; padding: 1px 5px; }
.pa.current { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(201,165,74,.35); }
.pa.sideways { transform: rotate(-4deg); }
.pa.fow { background: #8e9a86; }
.pa.facedown { background: repeating-linear-gradient(45deg, #4a5143, #4a5143 8px, #3f463a 8px, #3f463a 16px); color: var(--ink); }
.phase { flex: 1; overflow: auto; padding: 18px 20px; }
.walk { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.prompt { position: sticky; top: 0; }
.prompt .kind { text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; color: var(--accent); font-weight: 700; }
.prompt .q { font-size: 1.35rem; line-height: 1.4; margin: 8px 0 14px; }
.prompt .q .cond { text-decoration: underline; text-underline-offset: 4px; }
.prompt .ask { color: var(--muted); margin-bottom: 12px; }
.prompt .answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tbs { margin: 6px 0 14px; padding-left: 22px; }
.tbs li { margin: 3px 0; }
.helpers { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 16px; }
.steps { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.steps .st { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); font-size: .85rem; }
.steps .st.on { border-color: var(--accent); color: var(--accent); }
.steps .st.done { color: var(--ok); border-color: #4b6339; }
.unitgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.unitbtn { min-height: 70px; border-radius: 12px; background: var(--paper); color: var(--paper-ink); border: none; font-weight: 750; padding: 8px 12px; text-align: left; display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.unitbtn small { font-weight: 500; display: block; color: #5d543a; }
.unitbtn.fow { background: #8e9a86; }

/* Editor */
.editor { display: grid; grid-template-columns: minmax(320px, 0.85fr) minmax(0, 1.15fr); gap: 18px; align-items: start; }
.photo-wrap { position: relative; background: #111; border-radius: 10px; overflow: hidden; touch-action: none; min-height: 200px; display: grid; place-items: center; }
.photo-wrap canvas { max-width: 100%; max-height: 60vh; display: block; }
.photo-wrap .crop { position: absolute; border: 2px dashed var(--accent); background: rgba(201,165,74,.12); pointer-events: none; }
.progress { height: 8px; background: #111; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.line-ed { border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--panel-2); display: flex; flex-direction: column; gap: 8px; }
.line-ed .sub { margin-left: 26px; display: flex; flex-direction: column; gap: 8px; }
.line-ed .hdr { display: flex; gap: 8px; align-items: center; }
.line-ed .hdr input.lbl { width: 64px; text-align: center; font-weight: 700; }
.line-ed textarea.cond { text-decoration: underline; text-underline-offset: 3px; }
.line-ed .two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.issues { color: #e2a08f; font-size: .9rem; }
.issues li { margin: 2px 0; }

/* Modal + toast */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: min(760px, 100%); max-height: 90vh; display: flex; flex-direction: column; }
.modal.wide { width: min(1180px, 100%); }
.modal .mh { padding: 16px 18px 6px; display: flex; justify-content: space-between; align-items: center; }
.modal .mb { padding: 8px 18px; overflow: auto; }
.modal .mf { padding: 12px 18px 16px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #0e100c; border: 1px solid var(--line); padding: 12px 20px; border-radius: 12px; z-index: 80; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }
.die { font-size: 4.5rem; font-weight: 800; text-align: center; padding: 10px 0; color: var(--accent); }
.logl { font-size: .9rem; border-bottom: 1px solid var(--line); padding: 6px 0; display: flex; gap: 10px; }
.logl .r { color: var(--muted); width: 44px; flex: none; }
.banner { background: #3b3420; border: 1px solid #6a5a2c; color: #f1dfa6; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; }
.rules li { margin: 4px 0; line-height: 1.4; }

@media (orientation: portrait) {
  .walk, .editor { grid-template-columns: 1fr; }
  .modes { grid-template-columns: 1fr; }
  .rail { width: 74px; }
}
