:root {
  --bg: #efe6d6;
  --paper: #fffaf1;
  --paper-2: rgba(255, 250, 241, .78);
  --paper-3: rgba(247, 240, 228, .92);
  --ink: #3c3228;
  --muted: #7a6c5d;
  --line: #dccdb6;
  --sage: #5a7d5e;
  --sage-deep: #3e5a42;
  --terra: #c45c3a;
  --gold: #c9a054;
  --green: #5f7f5a;
  --neutral: #d8d0c3;
  --redbrown: #8c3f2c;
  --shadow: 0 10px 32px rgba(60, 42, 24, .14);
  --serif: "Noto Serif CJK SC", "Noto Serif SC", "Songti SC", "Source Han Serif SC", serif;
  --sans: "Noto Sans CJK SC", "Noto Sans SC", "PingFang SC", "Source Han Sans SC", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
}
button, input { font-family: inherit; color: inherit; }
[hidden] { display: none !important; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }

.app {
  height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: 1fr auto;
  background: #2b241c;
}

/* ----- stage / painting ----- */
.stage {
  position: relative;
  overflow: hidden;
  min-height: 0;
  background: #cbbca6;
}
.paintings, .painting {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.painting {
  object-fit: cover;
  object-position: center 45%;
  opacity: 0;
  transition: opacity .7s ease;
  filter: saturate(.96) contrast(1.02);
}
.painting.is-front { opacity: 1; z-index: 1; }

.paper-grain, .vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
.paper-grain {
  opacity: .18;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/><feColorMatrix values='0 0 0 0 0.35  0 0 0 0 0.28  0 0 0 0 0.2  0 0 0 .45 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
.vignette {
  background:
    linear-gradient(to bottom, rgba(40,28,16,.28) 0%, transparent 18%, transparent 72%, rgba(30,22,14,.45) 100%),
    radial-gradient(120% 80% at 50% 40%, transparent 55%, rgba(30,22,14,.28) 100%);
}
.app.mood-alert .vignette {
  background:
    linear-gradient(to bottom, rgba(80,30,16,.22) 0%, transparent 20%, transparent 70%, rgba(40,20,12,.5) 100%),
    radial-gradient(120% 80% at 50% 40%, transparent 52%, rgba(70,25,12,.28) 100%);
}
.app.mood-fleeing .vignette {
  background:
    linear-gradient(to bottom, rgba(40,28,16,.2) 0%, transparent 18%, transparent 70%, rgba(30,22,14,.5) 100%),
    radial-gradient(120% 80% at 50% 40%, transparent 50%, rgba(30,22,14,.32) 100%);
}
.app.mood-caught .vignette {
  background:
    linear-gradient(to bottom, rgba(40,28,16,.22) 0%, transparent 20%, transparent 72%, rgba(30,22,14,.42) 100%);
}

/* ----- HUD ----- */
.hud {
  position: absolute;
  z-index: 4;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px 0;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #f7f0e4;
  text-shadow: 0 1px 8px rgba(30,20,10,.45);
}
.brand h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: .28em;
  line-height: 1;
}
.brand-mark {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--terra);
  box-shadow: 0 0 0 4px rgba(196,92,58,.28);
}

.loc {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--paper-2);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,250,241,.35);
  font-size: 13px;
  letter-spacing: .12em;
  color: var(--sage-deep);
}

.stats {
  margin-left: auto;
  display: flex;
  gap: 8px;
}
.stat {
  min-width: 64px;
  padding: 6px 10px 5px;
  border-radius: 12px;
  background: var(--paper-2);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,250,241,.35);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.stat em {
  font-style: normal;
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 650;
  line-height: 1.1;
}
.stat span {
  font-size: 10px;
  letter-spacing: .14em;
  color: var(--muted);
}
.stat.credit {
  min-width: 118px;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.stat.credit span { margin-top: 0; }
.bar {
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: #e4d9c8;
  overflow: hidden;
  min-width: 48px;
}
.bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #7d9a78, #5a7d5e);
  border-radius: inherit;
  width: 0;
  transition: width .45s ease;
}
.stat.heat {
  background: rgba(243, 221, 215, .86);
  color: var(--terra);
}
.stat.heat span { color: var(--terra); }
.is-hidden { display: none !important; }

/* ----- nameplate ----- */
.nameplate {
  position: absolute;
  z-index: 4;
  left: 20px;
  bottom: 18px;
  color: var(--ink);
  max-width: min(46vw, 360px);
  pointer-events: none;
  padding: 8px 14px 9px;
  border-radius: 14px;
  background: var(--paper-2);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,250,241,.4);
}
.nameplate-title {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: .18em;
  line-height: 1.2;
}
.nameplate-sub {
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  letter-spacing: .16em;
  opacity: .9;
}
.wariness {
  display: inline-flex;
  gap: 4px;
}
.wariness i {
  width: 7px; height: 7px;
  border-radius: 50%;
  border: 1px solid rgba(247,240,228,.8);
  background: transparent;
}
.wariness i.on {
  background: #e8c48a;
  border-color: #e8c48a;
}

/* ----- toast ----- */
.toast {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 22%;
  transform: translate(-50%, -8px);
  padding: 10px 22px;
  border-radius: 999px;
  background: rgba(255,250,241,.9);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-family: var(--serif);
  letter-spacing: .2em;
  font-size: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s ease, transform .35s ease;
}
.toast.is-on {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ----- bottom dock ----- */
.bottom {
  z-index: 6;
  background:
    linear-gradient(to top, #f3eadc, #efe6d6);
  border-top: 1px solid #e4d6c0;
  padding: 8px 16px calc(12px + env(safe-area-inset-bottom));
  display: grid;
  gap: 8px;
}
.menu {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 2px;
  justify-content: center;
}
.menu button {
  appearance: none;
  background: none;
  border: 0;
  padding: 6px 11px;
  color: var(--muted);
  letter-spacing: .14em;
  font-size: 12.5px;
  border-radius: 999px;
  position: relative;
}
.menu button:hover, .menu button.is-on {
  color: var(--ink);
  background: rgba(255,250,241,.7);
}
.menu .badge {
  position: absolute;
  top: 2px; right: 2px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 99px;
  background: var(--terra);
  color: #fffaf1;
  font-size: 9px;
  letter-spacing: 0;
  display: grid;
  place-items: center;
}

.dock {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 16px 24px;
  min-height: 84px;
}
.cluster {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.cluster-label {
  font-size: 11px;
  letter-spacing: .28em;
  color: var(--muted);
}
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

/* approach swatches */
.swatch {
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 2px solid #fffaf1;
  box-shadow: 0 0 0 1px #cbbba3, 0 4px 10px rgba(60,42,24,.12);
  display: grid;
  place-items: end center;
  padding-bottom: 6px;
  color: #fffaf1;
  text-shadow: 0 1px 2px rgba(0,0,0,.25);
  font-size: 11px;
  letter-spacing: .12em;
  background: #ccc;
  transition: transform .15s ease, box-shadow .15s ease;
}
.swatch.tone-green { background: radial-gradient(circle at 35% 30%, #7d9a78, #5a7d5e 58%, #3e5a42); }
.swatch.tone-neutral { background: radial-gradient(circle at 35% 30%, #efe8dc, #d8d0c3 60%, #b7ae9f); color: var(--ink); text-shadow: none; }
.swatch.tone-redbrown { background: radial-gradient(circle at 35% 30%, #b85a40, #8c3f2c 58%, #6a2c1e); }
.swatch:hover { transform: translateY(-2px); }
.swatch.is-on {
  box-shadow: 0 0 0 3px var(--ink), 0 6px 14px rgba(60,42,24,.16);
  transform: translateY(-1px);
}

.posture, .btn, .gear {
  appearance: none;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 18px;
  letter-spacing: .14em;
  font-size: 14px;
  box-shadow: 0 1px 0 rgba(60,50,40,.04);
  transition: background .15s, transform .1s, box-shadow .15s, border-color .15s;
}
.posture { min-width: 96px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.posture svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.6; }
.posture:hover, .btn:hover, .gear:hover { background: #f6eee0; }
.posture:active, .btn:active, .gear:active { transform: scale(.98); }
.posture.is-on, .btn.is-on {
  border-color: var(--ink);
  background: #f4ead8;
  box-shadow: 0 0 0 1px var(--ink);
}
.btn.solid {
  background: var(--sage);
  color: #fffaf1;
  border-color: transparent;
}
.btn.solid:hover { background: var(--sage-deep); }
.btn.danger {
  background: var(--terra);
  color: #fffaf1;
  border-color: transparent;
}
.btn:disabled, .gear:disabled {
  opacity: .42;
  cursor: not-allowed;
  transform: none;
}

.gear {
  min-width: 132px;
  border-radius: 16px;
  padding: 10px 16px 9px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.gear b { font-weight: 600; letter-spacing: .12em; }
.gear small { color: var(--muted); letter-spacing: .08em; font-size: 11px; }

.dock-msg {
  color: var(--muted);
  letter-spacing: .16em;
  font-size: 13px;
  align-self: center;
}

/* ----- sheets / overlays ----- */
.sheet, .confirm, .letter {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(40, 30, 20, .38);
}
.sheet-card, .confirm-card, .letter-card {
  position: relative;
  width: min(720px, 100%);
  max-height: min(82vh, 760px);
  background: var(--paper);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: rise .28s ease;
}
@keyframes rise {
  from { transform: translateY(24px); opacity: .6; }
  to { transform: none; opacity: 1; }
}
.sheet-head {
  display: flex;
  align-items: center;
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: .2em;
  font-size: 18px;
}
.icon-btn {
  margin-left: auto;
  width: 36px; height: 36px;
  border: 0; background: none;
  font-size: 22px;
  color: var(--muted);
  border-radius: 50%;
}
.icon-btn:hover { background: #f3eadc; color: var(--ink); }
.sheet-body {
  padding: 16px 18px 28px;
  overflow: auto;
}

.confirm, .letter { place-items: center; }
.confirm-card, .letter-card {
  width: min(420px, calc(100% - 32px));
  border-radius: 18px;
  padding: 22px 22px 18px;
  max-height: none;
}
.confirm-card p, .letter-body {
  font-family: var(--serif);
  letter-spacing: .08em;
  line-height: 1.7;
  white-space: pre-wrap;
  margin-bottom: 18px;
}
.confirm-actions, .letter-card { }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.letter-card { align-items: stretch; }
.letter-card .btn { align-self: flex-end; }
.letter-body {
  background: #f7f0e4;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 16px 18px;
  min-height: 120px;
}

/* ----- panel contents ----- */
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.card {
  background: #f7f0e4;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card h3 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: .1em;
  font-size: 16px;
}
.card .meta {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .08em;
}
.card .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.card .actions .btn, .card .actions .gear { padding: 6px 12px; font-size: 12.5px; min-width: 0; }
.meter { height: 7px; background: #e4d9c8; border-radius: 99px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--sage); }
.meter.san i { background: var(--terra); }
.meter.shine i { background: var(--gold); }
.meter-row { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); letter-spacing: .08em; }

.continent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}
.continent {
  appearance: none;
  text-align: left;
  background: #f7f0e4;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 14px 12px;
  letter-spacing: .08em;
}
.continent:hover { border-color: #c9b89a; }
.continent.is-here {
  border-color: var(--sage);
  box-shadow: inset 0 0 0 1px var(--sage);
}
.continent b { display: block; font-family: var(--serif); font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.continent small { color: var(--muted); }

.dex-list { display: flex; flex-direction: column; gap: 10px; }
.dex-item {
  padding: 10px 12px;
  border-radius: 12px;
  background: #f7f0e4;
  border: 1px solid var(--line);
}
.dex-item h3 { font-family: var(--serif); font-size: 16px; letter-spacing: .1em; }
.dex-item p { margin-top: 4px; color: #5c5146; font-size: 13px; line-height: 1.6; letter-spacing: .04em; }

.market-row, .catalog-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px solid #efe3d2;
  font-size: 14px;
}
.market-row.is-hot { color: var(--terra); }
.muted { color: var(--muted); }
.empty-hint {
  color: var(--muted);
  letter-spacing: .12em;
  text-align: center;
  padding: 24px 8px;
}

/* busy */
.app.is-busy { cursor: wait; }
.app.is-busy .dock, .app.is-busy .menu { pointer-events: none; opacity: .75; }

@media (max-width: 720px) {
  .nameplate-title { font-size: 22px; letter-spacing: .12em; }
  .hud { padding: 12px 12px 0; gap: 8px; flex-wrap: wrap; }
  .brand h1 { font-size: 18px; letter-spacing: .2em; }
  .stats { width: 100%; justify-content: flex-end; }
  .dock { min-height: 96px; }
  .swatch { width: 50px; height: 50px; }
}
