/* =========================================================================
   冒險認證書 — 王園長的秘密基地
   Two layers live here:
     .bar / .shell / .panel  — the workshop UI (dark, forest floor)
     .cert                   — the certificate itself (white paper, 1055×1491)
   The paper never inherits UI styling; every certificate rule is .cert-scoped.
   ========================================================================= */

:root {
  /* paper */
  --ink:       #4a3b2f;
  --ink-deep:  #57310f;
  --frame:     #5f3514;
  --olive:     #45552f;
  --tan:       #a8907e;
  --sage:      #7e8d72;

  /* workshop */
  --ui-bg:      #1d2517;
  --ui-surface: #27311f;
  --ui-raised:  #313d27;
  --ui-line:    #435234;
  --ui-text:    #ece7d6;
  --ui-dim:     #9aa789;
  --ui-accent:  #e0a83f;
  --ui-accent-d:#3a2c0d;

  --serif: "Noto Serif TC", "Songti TC", "Source Han Serif TC", "PMingLiU", serif;
  --sans:  "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--ui-bg);
  color: var(--ui-text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ------------------------------------------------------ */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 60px;
  padding: 0 20px;
  background: var(--ui-surface);
  border-bottom: 1px solid var(--ui-line);
  position: sticky;
  top: 0;
  z-index: 30;
}

/* min-width:0 lets this absorb the whole shortfall when the bar is tight, so it
   must clip too — without overflow:hidden the nowrap text keeps painting at full
   width and runs under .bar-actions instead of being trimmed. */
.bar-mark {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}

.bar-mark-base {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 2px;
  color: var(--ui-text);
  white-space: nowrap;
}

.bar-mark-doc {
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--ui-dim);
  white-space: nowrap;
}

.bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- buttons ------------------------------------------------------ */

.btn {
  appearance: none;
  border: 1px solid var(--ui-line);
  background: var(--ui-raised);
  color: var(--ui-text);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 1px;
  padding: 9px 16px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}

.btn:hover { background: #3b4930; border-color: #5b6d48; }

.btn:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
}

.btn[disabled] { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: var(--ui-accent-d);
  font-weight: 700;
}

.btn-primary:hover { background: #eeb84e; border-color: #eeb84e; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ui-dim);
}

.btn-ghost:hover { background: var(--ui-raised); color: var(--ui-text); }

/* ---------- layout ------------------------------------------------------- */

.shell {
  display: flex;
  align-items: flex-start;
  min-height: calc(100vh - 60px);
}

.panel {
  flex: 0 0 400px;
  width: 400px;
  align-self: stretch;
  background: var(--ui-surface);
  border-right: 1px solid var(--ui-line);
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
}

.panel[hidden] { display: none; }

.panel-scroll {
  overflow-y: auto;
  padding: 22px 20px 24px;
  flex: 1;
}

.stagewrap {
  flex: 1;
  min-width: 0;
  padding: 26px 26px 60px;
  display: flex;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 0%, #26311d 0%, var(--ui-bg) 62%);
}

.stagefit {
  position: relative;
  flex: none;
}

/* blank mode stacks a notice above the paper */
.stagewrap-stacked {
  flex-direction: column;
  align-items: center;
}

/* ---------- form controls ------------------------------------------------ */

.grp { margin-bottom: 26px; }

.grp-h {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.grp-h span {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 3px;
  color: var(--ui-accent);
  white-space: nowrap;
}

.grp-h::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--ui-line);
}

.fld { margin-bottom: 12px; }

.fld > label {
  display: block;
  font-size: 12px;
  letter-spacing: 1.5px;
  color: var(--ui-dim);
  margin-bottom: 6px;
}

.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* date inputs have a ~158px min-content width and grid items default to
   min-width:auto, so two columns overflow on the narrowest phones */
.row2 > * { min-width: 0; }

.inp {
  width: 100%;
  appearance: none;
  background: var(--ui-bg);
  border: 1px solid var(--ui-line);
  border-radius: 6px;
  color: var(--ui-text);
  font-family: var(--sans);
  font-size: 15px;
  padding: 10px 11px;
  transition: border-color .15s, box-shadow .15s;
}

.inp::placeholder { color: #6c795c; }

.inp:focus {
  outline: none;
  border-color: var(--ui-accent);
  box-shadow: 0 0 0 3px rgba(224,168,63,.18);
}

.inp-sel {
  appearance: none;
  padding-right: 34px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%239aa789' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 11px;
}

.inp-sel:disabled { color: var(--ui-dim); cursor: not-allowed; }

.withbtn {
  display: flex;
  gap: 8px;
}

.withbtn .inp { flex: 1; min-width: 0; }

.withbtn .btn { flex: none; padding: 9px 14px; }

.hint {
  font-size: 12px;
  line-height: 1.6;
  color: var(--ui-dim);
  margin: -4px 0 12px;
}

/* ---------- activity picker (mirrors the certificate cards) -------------- */

.picks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.pick {
  border: 1px solid var(--ui-line);
  border-top: 3px solid var(--pc, var(--ui-line));
  border-radius: 8px;
  background: var(--ui-bg);
  padding: 10px 10px 8px;
}

.pick-h {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
}

.pick-h b {
  font-family: var(--serif);
  font-size: 14px;
  letter-spacing: 1.5px;
  color: var(--pc, var(--ui-text));
  font-weight: 700;
}

.opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 4px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--ui-text);
  user-select: none;
}

.opt:hover { background: rgba(255,255,255,.05); }

/* the tick itself is drawn by the <i>; must not also catch .opt-inp */
.opt input[type="checkbox"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.opt i {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1.5px solid var(--pc, var(--ui-dim));
  flex: none;
  position: relative;
  transition: background .12s;
}

.opt input:checked + i {
  background: var(--pc, var(--ui-accent));
  box-shadow: inset 0 0 0 2px var(--ui-bg);
}

.opt input:focus-visible + i {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
}

.opt-inp {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--ui-line);
  color: var(--ui-text);
  font-family: var(--sans);
  font-size: 13.5px;
  padding: 2px 2px 3px;
}

.opt-inp::placeholder { color: #6c795c; }

.opt-inp:focus { outline: none; border-bottom-color: var(--ui-accent); }

.tally {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px dashed var(--ui-line);
  border-radius: 7px;
  font-size: 13px;
  color: var(--ui-dim);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.tally b {
  font-family: var(--serif);
  font-size: 22px;
  color: var(--ui-accent);
}

/* ---------- action bar --------------------------------------------------- */

.acts {
  border-top: 1px solid var(--ui-line);
  background: var(--ui-surface);
  padding: 14px 20px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.acts .btn-primary { grid-column: 1 / -1; }

/* ---------- notices ------------------------------------------------------ */

.notice {
  max-width: 1055px;
  margin: 0 auto 18px;
  padding: 12px 16px;
  border: 1px solid var(--ui-line);
  border-left: 3px solid var(--ui-accent);
  border-radius: 6px;
  background: var(--ui-surface);
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--ui-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.notice a { color: var(--ui-accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  background: var(--ui-accent);
  color: var(--ui-accent-d);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 11px 22px;
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 60;
}

.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* =========================================================================
   THE CERTIFICATE
   The paper IS the original artwork, drawn as the background of a fixed
   1055 x 1491 stage (A4 ratio) and scaled to fit by --s. Nothing here
   redraws the frame, ribbons, boxes or rules -- those are in the image.
   The only children are the filled-in values, positioned in artwork
   coordinates so they land on the printed rules.
   ========================================================================= */

.cert {
  position: relative;
  width: 1055px;
  height: 1491px;
  background: #fff center / 1055px 1491px no-repeat;
  overflow: hidden;
  transform: scale(var(--s, 1));
  transform-origin: top left;
  font-family: var(--serif);
  color: var(--ink);
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
}

.cert .ov {
  position: absolute;
  white-space: nowrap;
  line-height: 1;
  font-weight: 500;
  color: var(--ink);
}

/* bottom-centred on a printed rule */
.cert .ov-rule { transform: translate(-50%, -100%); }

/* centred in the name box */
.cert .ov-name {
  transform: translate(-50%, -50%);
  font-size: 58px;
  font-weight: 700;
  letter-spacing: 8px;
  text-indent: 8px;
}

/* a tick inside a printed circle, drawn with borders so html2canvas keeps it */
.cert .ov-tick {
  width: 20px;
  height: 20px;
}

.cert .ov-tick i {
  position: absolute;
  left: 6px;
  top: 1px;
  width: 6px;
  height: 12.5px;
  display: block;
  border-style: solid;
  border-width: 0 2.8px 2.8px 0;
  transform: rotate(42deg);
}

/* =========================================================================
   Responsive — the panel stacks above the paper on narrow screens
   ========================================================================= */

@media (max-width: 1000px) {
  .shell { flex-direction: column; }

  .panel {
    flex: none;
    width: 100%;
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--ui-line);
    order: 2;
  }

  .panel-scroll { overflow: visible; }

  .stagewrap {
    order: 1;
    width: 100%;
    padding: 16px 12px 24px;
  }

  .acts { position: sticky; bottom: 0; }
}

/* In view and blank mode the header carries the brand plus four actions, which
   need ~395px on their own. Below this they cannot share a row with the brand,
   so give them their own full-width row instead of squeezing the brand away. */
@media (max-width: 700px) {
  .bar {
    height: auto;
    flex-wrap: wrap;
    padding: 10px 12px;
    row-gap: 10px;
  }

  .bar-actions { flex: 1 1 100%; }

  .bar-actions .btn {
    flex: 1;
    min-width: 0;
    padding: 9px 6px;
    letter-spacing: 0;
  }
}

@media (max-width: 560px) {
  .bar-mark-doc { display: none; }
  .picks { grid-template-columns: 1fr; }
  .panel-scroll { padding: 18px 14px 20px; }
}

/* two date fields no longer fit side by side */
@media (max-width: 400px) {
  .row2 { grid-template-columns: 1fr; gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* =========================================================================
   Print — paper only, scaled to fill an A4 sheet edge to edge
   ========================================================================= */

@page { size: A4 portrait; margin: 0; }

@media print {
  html, body { background: #fff; height: auto; }
  .bar, .panel, .toast, .notice { display: none !important; }
  .shell { display: block; min-height: 0; }
  .stagewrap { padding: 0; background: none; display: block; }

  /* !important because fit() writes the on-screen size as inline styles,
     which would otherwise win and shrink the sheet. 793.7 x 1121.7 px is
     A4 at 96dpi; 1055 x 0.75232 lands exactly on it. */
  .stagefit {
    width: 793.7px !important;
    height: 1121.7px !important;
    overflow: hidden;
  }

  .cert {
    transform: scale(0.75232) !important;
    box-shadow: none;
  }
}
