/* ---------------------------------------------------------------------------
   人事风暴 — UI visual language, derived from the game's own art direction:
   an HR dossier on a desk at night. Paper stock (the same paper.webp that
   dresses the desk), ink-grey rules, one vermilion accent = the company seal,
   teal = data. Panels are documents: warm paper ground, a double hairline
   rule at the edge instead of a border-radius card, a filing tab at the top,
   and motion that settles like a sheet being laid down rather than fading in.
   Typeface class: a serif for headings and story (Songti / Georgia — the
   register of a printed personnel file), a humanist sans for data readouts.
--------------------------------------------------------------------------- */

:root {
  --paper:      #e9e1d0;
  --paper-2:    #dcd2bd;
  --paper-deep: #cabfa6;
  --ink:        #1b2027;
  --ink-soft:   #4a5058;
  --ink-faint:  #7d8189;
  --teal:       #2f6f74;
  --teal-lit:   #57a3a6;
  --vermil:     #b83f28;
  --vermil-lit: #d9634a;
  --amber:      #c68b3c;
  --night:      #080b10;

  --serif: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, "Times New Roman", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "WenQuanYi Zen Hei", "Helvetica Neue", Arial, sans-serif;

  --rule: 1px solid var(--ink);
  --hair: 1px solid rgba(27, 32, 39, 0.32);
  --settle: cubic-bezier(0.22, 0.9, 0.3, 1);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
*::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

html, body {
  margin: 0; padding: 0; height: 100%; width: 100%; overflow: hidden;
  background: var(--night); color: var(--paper);
  font-family: var(--sans);
  overscroll-behavior: none;
  touch-action: manipulation;
}

#app { position: fixed; inset: 0; }
#stage-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: block; }
#ui { position: absolute; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }

/* Vignette + paper-warm grade over the render, so 3D and UI read as one book. */
#ui::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 42%, rgba(0,0,0,0) 42%, rgba(4,7,11,0.62) 100%);
}

/* --- the document panel: the base surface of every screen ---------------- */

.doc {
  position: relative;
  background-color: var(--paper);
  background-image: var(--paper-tex, none);
  background-size: 340px 340px;
  background-blend-mode: multiply;
  color: var(--ink);
  border: var(--rule);
  box-shadow: 0 1px 0 rgba(27,32,39,0.9), 0 18px 40px rgba(0,0,0,0.55);
}
/* the inner double rule that says "form", not "card" */
.doc::after {
  content: ""; position: absolute; inset: 4px; border: var(--hair); pointer-events: none;
}
/* the filing tab */
.doc.tabbed::before {
  content: attr(data-tab);
  position: absolute; top: -1px; left: 16px; transform: translateY(-100%);
  background: var(--ink); color: var(--paper);
  font-family: var(--sans); font-size: 12px; letter-spacing: 0.16em;
  padding: 3px 12px 2px;
}

/* --- top bar: week, action points, crisis line --------------------------- */

#topbar {
  position: absolute;
  top: calc(10px + var(--safe-t)); left: calc(12px + var(--safe-l)); right: calc(12px + var(--safe-r));
  display: flex; gap: 10px; align-items: stretch;
}
#weekbadge {
  flex: 0 0 auto; display: flex; flex-direction: column; justify-content: center;
  padding: 7px 14px; min-width: 92px;
}
#weekbadge .wk { font-family: var(--serif); font-size: 20px; font-weight: 700; line-height: 1; }
#weekbadge .ap { font-size: 12px; color: var(--ink-soft); letter-spacing: 0.06em; margin-top: 4px; }
#weekbadge .pips { display: inline-flex; gap: 4px; margin-left: 6px; vertical-align: -1px; }
#weekbadge .pip { width: 9px; height: 9px; border: 1px solid var(--ink); background: transparent; }
#weekbadge .pip.on { background: var(--vermil); border-color: var(--vermil); }

#crisisbar { flex: 1 1 auto; display: flex; align-items: center; padding: 7px 14px; min-width: 0; }
#crisisbar .k { font-size: 12px; letter-spacing: 0.2em; color: var(--vermil); flex: 0 0 auto; margin-right: 10px; }
#crisisbar .v {
  font-family: var(--serif); font-size: 13.5px; line-height: 1.35; color: var(--ink);
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* --- metric strip: six company indicators ------------------------------- */

#metrics {
  position: absolute; top: calc(64px + var(--safe-t)); right: calc(12px + var(--safe-r));
  width: 208px; padding: 10px 12px 12px;
}
/* the filing tab already names this panel; the inner heading would say it twice */
#metrics h4 { display: none; }
.metric { margin-bottom: 7px; }
.metric .row { display: flex; justify-content: space-between; align-items: baseline; font-size: 12.5px; }
.metric .lab { color: var(--ink-soft); letter-spacing: 0.04em; }
.metric .num { font-family: var(--serif); font-weight: 700; font-size: 13px; color: var(--ink); }
.metric .num .delta { font-size: 12px; font-family: var(--sans); margin-left: 5px; font-weight: 600; }
.delta.pos { color: var(--teal); } .delta.neg { color: var(--vermil); }
.metric .bar { height: 5px; background: rgba(27,32,39,0.14); margin-top: 3px; position: relative; }
.metric .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--teal); transition: width 0.5s var(--settle); }
.metric.low .bar i { background: var(--vermil); }
.metric.ipo .bar i { background: var(--amber); }

/* --- the desk list: investigable documents and people -------------------- */

#deskwrap {
  position: absolute;
  left: calc(12px + var(--safe-l)); bottom: calc(52px + var(--safe-b));
  top: calc(64px + var(--safe-t));
  width: min(420px, 46vw);
  display: flex; flex-direction: column; justify-content: flex-end; gap: 7px;
  overflow-x: hidden !important;
  overflow-y: auto;
  padding-right: 4px;
  z-index: 15;
}
.node {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 11px; cursor: pointer; min-height: 46px;   /* a struck target, not a list row */
  -webkit-tap-highlight-color: transparent;
  background-color: var(--paper-2);
  border: var(--rule);
  transform: translateX(0); transition: transform 0.18s var(--settle), background-color 0.18s;
  position: relative;
}
.node .ic {
  flex: 0 0 auto; width: 22px; height: 22px; border: 1px solid var(--ink);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--ink);
}
.node.kind-person .ic { border-radius: 50%; }
.node .tx { flex: 1 1 auto; min-width: 0; }
.node .nm { font-family: var(--serif); font-size: 13.5px; color: var(--ink); line-height: 1.2; }
.node .st { font-size: 12px; color: var(--ink-faint); letter-spacing: 0.08em; margin-top: 2px; }
.node.read { background-color: rgba(202,191,166,0.55); }
.node.read .nm { color: var(--ink-soft); }
.node.sel { background-color: var(--paper); transform: translateX(9px); }
.node.sel::before {
  content: ""; position: absolute; left: -9px; top: 0; bottom: 0; width: 4px; background: var(--vermil);
}
/* struck: the card takes the stamp for a beat, the way a hand comes down on it */
.node:active { transform: translateX(9px) scale(0.985); background-color: var(--paper); }
@media (hover: hover) { .node:hover { background-color: var(--paper); } }
.node.decide { background-color: #2b3138; border-color: #2b3138; }
.node.decide .nm { color: var(--paper); }
.node.decide .st { color: rgba(233,225,208,0.55); }
.node.decide .ic { border-color: var(--paper-2); color: var(--paper-2); }
.node.decide.sel { background-color: var(--vermil); border-color: var(--vermil); }
.node.decide.sel::before { background: var(--ink); }

/* --- reading overlay: a document laid on the desk ------------------------ */

#overlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(88px + var(--safe-b)) calc(12px + var(--safe-l));
  background: rgba(6,9,13,0.55);
  z-index: 50;
}
#overlay.on { display: flex; }
#sheet {
  width: min(760px, 100%); max-height: 100%;
  display: flex; flex-direction: column; overflow: hidden;
  animation: settle 0.24s var(--settle);
}
@keyframes settle {
  from { transform: translateY(14px) rotate(-0.4deg); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
#sheet .head {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px 10px;
  border-bottom: var(--rule); flex: 0 0 auto;
}
#sheet .head img {
  width: 54px; height: 54px; object-fit: cover; flex: 0 0 auto;
  border: 1px solid var(--ink); filter: saturate(0.85);
}
#sheet .head h3 { margin: 0; font-family: var(--serif); font-size: 17px; color: var(--ink); }
#sheet .head .sub { font-size: 12px; letter-spacing: 0.2em; color: var(--vermil); margin-top: 3px; }
#sheet .body {
  padding: 14px 18px; overflow-y: auto; flex: 1 1 auto;
  font-family: var(--serif); font-size: 14.5px; line-height: 1.72; color: var(--ink);
  text-indent: 2em;
}
#sheet .clue {
  margin: 12px 18px 0; padding: 9px 12px; border-left: 3px solid var(--teal);
  background: rgba(47,111,116,0.09); font-size: 12.5px; line-height: 1.55; color: var(--teal);
  font-family: var(--sans); text-indent: 0; flex: 0 0 auto;
}
#sheet .foot {
  padding: 9px 16px 11px; font-size: 12px; color: var(--ink-faint);
  letter-spacing: 0.08em; border-top: var(--hair); flex: 0 0 auto;
}

/* option list inside the decision sheet */
.opts { padding: 8px 14px 14px; overflow-y: auto; flex: 1 1 auto; }
.opt {
  border: var(--rule); background: var(--paper-2); padding: 10px 13px; margin-bottom: 8px;
  cursor: pointer; position: relative; transition: transform 0.16s var(--settle), background 0.16s;
  min-height: 50px; display: flex; flex-direction: column; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.opt .t { font-family: var(--serif); font-size: 14px; color: var(--ink); }
.opt .n { font-size: 12px; color: var(--ink-faint); margin-top: 3px; font-family: var(--sans); }
.opt.sel { background: var(--paper); transform: translateX(8px); }
.opt.sel::before { content: ""; position: absolute; left: -8px; top: 0; bottom: 0; width: 4px; background: var(--vermil); }
.opt { min-height: 48px; display: flex; flex-direction: column; justify-content: center;
        -webkit-tap-highlight-color: transparent; }
.opt:active { transform: translateX(8px) scale(0.99); background: var(--paper); }
@media (hover: hover) { .opt:hover { background: var(--paper); } }
.opt.locked { opacity: 0.5; }
.opt.locked .t { text-decoration: line-through; text-decoration-color: rgba(27,32,39,0.35); }

/* --- weekly settlement / overview --------------------------------------- */

#settle { position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(88px + var(--safe-b)) calc(12px + var(--safe-l));
  background: rgba(6,9,13,0.42); z-index: 50; }
#settle.on { display: flex; }
#settlecard { width: min(720px, 100%); max-height: 100%; display: flex; flex-direction: column; overflow: hidden;
  animation: settle 0.28s var(--settle); }
#settlecard h3 { margin: 0; padding: 12px 18px 9px; font-family: var(--serif); font-size: 18px;
  border-bottom: var(--rule); color: var(--ink); flex: 0 0 auto; }
#settlecard .narr { padding: 12px 18px 4px; font-family: var(--serif); font-size: 14px; line-height: 1.7;
  color: var(--ink); text-indent: 2em; overflow-y: auto; }
#ledger { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; padding: 10px 14px 12px;
  background: transparent; flex: 0 0 auto; }
.led { border: var(--hair); padding: 7px 9px; background: rgba(255,255,255,0.28); }
.led .l { font-size: 12px; letter-spacing: 0.1em; color: var(--ink-soft); }
.led .v { font-family: var(--serif); font-size: 16px; font-weight: 700; color: var(--ink); margin-top: 2px; }
.led .d { font-size: 12px; font-weight: 600; margin-left: 6px; }

/* --- title / ending ------------------------------------------------------ */

#screen { position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  padding: calc(16px + var(--safe-t)) calc(14px + var(--safe-r)) calc(92px + var(--safe-b)) calc(14px + var(--safe-l)); z-index: 50; }
#screen.on { display: flex; }
#screencard { width: min(680px, 100%); max-height: 100%; overflow-y: auto; padding: 22px 26px 20px; }
#screencard .kicker { font-size: 12.5px; letter-spacing: 0.34em; color: var(--vermil); }
#screencard h1 {
  margin: 6px 0 2px; font-family: var(--serif); font-size: clamp(30px, 6.4vw, 52px);
  letter-spacing: 0.1em; color: var(--ink); line-height: 1.05;
}
#screencard h2 { margin: 0 0 14px; font-family: var(--sans); font-size: 12.5px; letter-spacing: 0.2em;
  color: var(--ink-soft); font-weight: 500; }
#screencard p { font-family: var(--serif); font-size: 14.5px; line-height: 1.75; color: var(--ink);
  text-indent: 2em; margin: 0 0 12px; }
#screencard .seal-line { display: flex; align-items: center; gap: 10px; margin-top: 14px;
  padding-top: 12px; border-top: var(--hair); font-size: 12px; color: var(--ink-soft); letter-spacing: 0.06em; }
#screencard .seal-line .mark { width: 26px; height: 26px; border: 2px solid var(--vermil); border-radius: 50%;
  color: var(--vermil); display: grid; place-items: center; font-family: var(--serif); font-size: 13px; }
#finaltable { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }

/* --- self-drawn touch control, in the game's own language ---------------
   The room chose direct pointing: every card, résumé, dossier and dialogue
   option IS the control, sized for a thumb and struck where it sits. What a
   card cannot carry — confirm on a screen with nothing to point at — falls to
   the company seal bottom-right, the same vermilion stamp the 3D dossier
   wears. Bottom-LEFT is deliberately left empty, so no card ever hides under
   a thumb resting there. Hidden on a fine pointer until the first touch.  */

#touch {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none !important;
  z-index: 20;
}
#touch.on { display: block; }
#seal {
  position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(18px + var(--safe-b));
  width: 96px; height: 96px; border-radius: 8px; touch-action: none;
  background: linear-gradient(160deg, var(--vermil-lit), var(--vermil));
  border: 3px solid #7d2a19;
  color: #f6ece0; display: grid; place-items: center;
  font-family: var(--serif); font-size: 30px; letter-spacing: 0.05em; line-height: 1;
  box-shadow: 0 6px 18px rgba(0,0,0,0.55), inset 0 0 0 2px rgba(246,236,224,0.30);
  transition: transform 0.07s ease-out, filter 0.07s;
  pointer-events: auto !important;
  z-index: 25;
}
#seal:active, #seal.press { transform: scale(0.93) rotate(-2deg); filter: brightness(1.15); }
#seal .cap { position: absolute; bottom: 6px; left: 0; right: 0; text-align: center;
  font-family: var(--sans); font-size: 12px; letter-spacing: 0.14em; opacity: 0.8; }

/* --- hint line + mute ---------------------------------------------------- */

#hint {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + var(--safe-b));
  font-size: 12.5px; letter-spacing: 0.08em; color: rgba(233,225,208,0.82);
  background: rgba(8,11,16,0.55); padding: 5px 14px; border: 1px solid rgba(233,225,208,0.18);
  text-align: center; max-width: 60vw;
}
#mute {
  position: absolute; top: calc(10px + var(--safe-t)); right: calc(12px + var(--safe-r));
  width: 30px; height: 30px; display: none; place-items: center;
  background: rgba(8,11,16,0.6); border: 1px solid rgba(233,225,208,0.25);
  color: var(--paper); font-size: 13px; cursor: pointer; z-index: 6;
}
#mute.on { display: grid; }

/* --- responsive: phone landscape (2.16:1, 390px tall) ------------------- */

@media (max-height: 460px) {
  #metrics { width: 176px; padding: 7px 9px 8px; top: calc(56px + var(--safe-t)); }
  #metrics h4 { margin-bottom: 5px; }
  .metric { margin-bottom: 4px; }
  .metric .bar { height: 4px; }
  .metric .row { font-size: 12px; }
  .metric .num { font-size: 12px; }
  #deskwrap { width: min(340px, 44vw); bottom: calc(46px + var(--safe-b)); top: calc(54px + var(--safe-t)); gap: 5px; }
  .node { min-height: 40px; }
  .node { padding: 5px 8px; gap: 8px; }
  .node .nm { font-size: 12px; }
  .node .st { font-size: 11px; }
  #weekbadge { padding: 5px 10px; min-width: 78px; }
  #weekbadge .wk { font-size: 16px; }
  #crisisbar .v { font-size: 12px; -webkit-line-clamp: 2; }
  #sheet .body { font-size: 13px; line-height: 1.6; padding: 10px 14px; }
  #sheet .head { padding: 9px 13px 8px; }
  #sheet .head img { width: 44px; height: 44px; }
  #sheet .head h3 { font-size: 15px; }
  #screencard { padding: 14px 18px; }
  #screencard p { font-size: 13px; line-height: 1.6; margin-bottom: 8px; }
  #ledger { grid-template-columns: repeat(6, 1fr); padding: 7px 10px 9px; }
  .led { padding: 5px 6px; } .led .v { font-size: 13px; } .led .l { font-size: 12px; }
  #seal { width: 70px; height: 70px; font-size: 20px; }
  #hint { font-size: 11.5px; padding: 4px 10px; bottom: calc(8px + var(--safe-b)); max-width: 44vw; }
}

/* --- portrait / mobile: panels stack neatly without overlapping --------- */

@media (orientation: portrait), (max-width: 768px) {
  #ui::before {
    background: radial-gradient(150% 80% at 50% 46%, rgba(0,0,0,0) 38%, rgba(4,7,11,0.56) 100%);
  }

  #topbar {
    top: calc(8px + var(--safe-t));
    left: calc(8px + var(--safe-l));
    right: calc(8px + var(--safe-r));
    display: flex;
    flex-direction: row;
    gap: 6px;
    align-items: stretch;
  }
  #weekbadge {
    padding: 5px 8px;
    min-width: 76px;
    flex: 0 0 auto;
  }
  #weekbadge .wk { font-size: 15px; }
  #weekbadge .ap { font-size: 10.5px; margin-top: 2px; }
  #weekbadge .pips { gap: 3px; margin-left: 4px; }
  #weekbadge .pip { width: 7px; height: 7px; }

  #crisisbar {
    padding: 5px 8px;
    flex: 1 1 auto;
    min-width: 0;
  }
  #crisisbar .k { font-size: 10.5px; margin-right: 6px; letter-spacing: 0.12em; }
  #crisisbar .v { font-size: 11.5px; line-height: 1.3; -webkit-line-clamp: 2; }

  #deskwrap {
    width: auto;
    left: calc(8px + var(--safe-l));
    right: calc(8px + var(--safe-r));
    top: calc(58px + var(--safe-t));
    bottom: calc(134px + var(--safe-b));
    max-height: 48vh;
    justify-content: flex-start;
    gap: 4px;
    padding-right: 0;
    overflow-x: hidden !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .node {
    min-height: 38px;
    padding: 5px 8px;
    gap: 7px;
    margin: 0;
  }
  .node .ic { width: 20px; height: 20px; font-size: 11px; }
  .node .nm { font-size: 12.5px; }
  .node .st { font-size: 11px; margin-top: 1px; }
  .node.sel { transform: translateX(5px); }
  .node.sel::before { left: -5px; width: 3px; }

  #metrics {
    position: absolute;
    top: auto;
    bottom: calc(34px + var(--safe-b));
    left: calc(8px + var(--safe-l));
    right: calc(8px + var(--safe-r));
    width: auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px 8px;
    padding: 6px 8px;
    z-index: 5;
    overflow: hidden;
  }
  .doc.tabbed::before {
    font-size: 10.5px;
    padding: 2px 7px 1px;
    left: 8px;
  }
  #metrics h4 { display: none; }
  .metric { margin-bottom: 0; }
  .metric .row { font-size: 11px; }
  .metric .lab { font-size: 11px; }
  .metric .num { font-size: 11.5px; }
  .metric .bar { height: 3.5px; margin-top: 2px; }

  #hint {
    bottom: calc(6px + var(--safe-b));
    font-size: 11px;
    padding: 3px 8px;
    max-width: 92vw;
    z-index: 6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #seal {
    width: 60px;
    height: 60px;
    font-size: 18px;
    right: calc(10px + var(--safe-r));
    bottom: calc(44px + var(--safe-b));
    z-index: 10;
    border-width: 2px;
  }
  #seal .cap { font-size: 9.5px; bottom: 3px; }

  #mute {
    top: calc(8px + var(--safe-t));
    right: calc(8px + var(--safe-r));
    width: 26px;
    height: 26px;
    font-size: 11px;
  }

  #overlay, #settle, #screen {
    padding: calc(6px + var(--safe-t)) calc(8px + var(--safe-r)) calc(10px + var(--safe-b)) calc(8px + var(--safe-l));
    z-index: 40;
  }
  #sheet, #settlecard, #screencard {
    width: 100%;
    max-height: 94vh;
    overflow-x: hidden;
    overflow-y: auto;
  }
  #sheet .head { padding: 8px 10px; gap: 8px; }
  #sheet .head img { width: 40px; height: 40px; }
  #sheet .head h3 { font-size: 15px; }
  #sheet .head .sub { font-size: 11px; }
  #sheet .body { font-size: 13px; line-height: 1.55; padding: 8px 12px; }
  #sheet .clue { font-size: 11.5px; margin: 6px 10px 0; padding: 5px 8px; }
  #sheet .foot { font-size: 11px; padding: 6px 10px; }
  .opts { padding: 6px 8px 8px; }
  .opt { padding: 7px 9px; min-height: 40px; margin-bottom: 5px; }
  .opt .t { font-size: 12.5px; }
  .opt .n { font-size: 11px; }
  #screencard { padding: 14px 16px; }
  #screencard h1 { font-size: clamp(24px, 7vw, 36px); }
  #screencard p { font-size: 13px; line-height: 1.6; }
  #ledger { grid-template-columns: repeat(3, 1fr); padding: 6px 8px; gap: 4px; }
  .led { padding: 4px 6px; }
  .led .l { font-size: 10.5px; }
  .led .v { font-size: 13px; }
}
