@font-face { font-family: "Sign"; src: url(fonts/oswald.woff2) format("woff2"); font-weight: 200 700; font-display: block; }
@font-face { font-family: "Body"; src: url(fonts/fira-400.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Body"; src: url(fonts/fira-600.woff2) format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Body"; src: url(fonts/fira-700.woff2) format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --paper: #EFE6D2; --grass: #B9C98A; --leaf: #3F6B3A; --gravel: #D9C7A0; --gravel-edge: #A88F63;
  --water: #6FA8B5; --ink: #2A2620; --enamel: #2F5A47; --enamel-dk: #24463A; --terra: #C4552F;
  --mustard: #D9A521; --brick: #A3362A; --cream: #F4ECD8;
  --menu-w: 248px; --top-h: 58px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--enamel-dk); color: var(--ink);
  font-family: "Body", system-ui, sans-serif; -webkit-user-select: none; user-select: none; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }
img { -webkit-user-drag: none; }
.num, .price { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

#app { position: fixed; inset: 0; display: grid;
  grid-template-columns: var(--menu-w) minmax(0, 1fr); grid-template-rows: var(--top-h) 1fr;
  grid-template-areas: "top top" "menu map";
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--enamel-dk); }

/* ---------- enamel plates ---------- */
.plate { background: var(--enamel); border: 2px solid var(--ink); border-radius: 7px;
  box-shadow: inset 0 0 0 2px #4E7A63, inset 0 0 0 3px var(--ink); color: var(--cream); }
.ledger { background: var(--cream); border: 2px solid var(--ink); border-radius: 8px;
  box-shadow: inset 0 0 0 3px var(--cream), inset 0 0 0 4px #B9A57C; }

/* ---------- top bar ---------- */
#top { grid-area: top; min-width: 0; display: flex; gap: 6px; align-items: stretch; padding: 6px 6px 4px; min-width: 0; }
#top .plate { display: flex; align-items: center; gap: 7px; padding: 0 10px; min-width: 0; white-space: nowrap; overflow: hidden; }
/* the badge owns its slot: nothing beside it may shrink into the title */
#top .logo { flex: 0 0 auto; }
#top .stat, #top .btn-round { flex-shrink: 1; }
#top .money { flex-shrink: 0; }
.logo img { width: 30px; height: 30px; object-fit: contain; }
.logo div { display: flex; flex-direction: column; line-height: 1; min-width: 0; }
.logo b { font-family: "Sign"; font-weight: 600; font-size: 22px; letter-spacing: .02em; color: var(--cream); text-transform: uppercase; }
.logo small { font-family: "Sign"; font-weight: 500; font-size: 9px; letter-spacing: .08em; color: #CFE0C9; text-transform: uppercase; margin-top: 2px; }
.stat b { font-family: "Sign"; font-weight: 600; font-size: 24px; letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.money b { color: var(--mustard); }
.money img, .vis img { width: 28px; height: 28px; object-fit: contain; }
.flow { gap: 10px !important; font-family: "Sign"; font-weight: 500; font-size: 17px; font-variant-numeric: tabular-nums; }
.flow .inc { color: #A9D79A; }
.flow .upk { color: #F08C78; }
.welf { flex: 1 1 180px; max-width: 300px; }
.welf .thermo { width: 20px; height: 32px; object-fit: contain; }
.welf .face { width: 28px; height: 28px; object-fit: contain; }
.gauge { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.gauge small { font-family: "Sign"; font-size: 10px; letter-spacing: .1em; }
.bar { height: 10px; background: var(--cream); border: 1.5px solid var(--ink); border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 80%; background: #6E9A4A; border-right: 1.5px solid var(--ink); transition: width .6s, background .6s; }
.clock { flex-direction: column; justify-content: center; gap: 0 !important; line-height: 1.05; }
.clock b { font-size: 17px; }
.clock small { font-family: "Sign"; font-size: 12px; }
.btn-round { font-family: "Sign"; font-size: 15px; font-weight: 600; justify-content: center; min-width: 44px; }
#soundBtn { font-size: 11px; letter-spacing: .06em; }
#soundBtn.off { color: #9DB3A6; text-decoration: line-through; }

/* ---------- side ledger ---------- */
#menu { grid-area: menu; min-width: 0; display: flex; flex-direction: column; min-height: 0; padding: 4px 6px 6px; gap: 6px;
  background: var(--enamel); border-right: 2px solid var(--ink); }
#tabs { display: flex; flex-direction: column; gap: 5px; }
.tab { position: relative; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 22px 0 10px;
  background: var(--cream); border: 2px solid var(--ink); border-radius: 4px 0 0 4px;
  clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 50%, calc(100% - 16px) 100%, 0 100%);
  font-family: "Sign"; font-weight: 600; font-size: 17px; letter-spacing: .03em; text-transform: uppercase; color: var(--enamel); text-align: left; }
.tab::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.tab img { width: 22px; height: 22px; object-fit: contain; }
.tab.on { background: var(--terra); color: var(--cream); }
.tab.on img { filter: brightness(0) invert(.95) sepia(.2); }
#cards { flex: 1; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 6px; padding-right: 2px;
  scrollbar-width: thin; scrollbar-color: #6A8F7B transparent; touch-action: pan-y; }
.section { font-family: "Sign"; font-weight: 600; color: var(--cream); font-size: 13px; letter-spacing: .1em; padding: 4px 2px 0; text-transform: uppercase; }
.note { color: #CFE0C9; font-size: 12px; padding: 0 2px; line-height: 1.3; }
.card { position: relative; display: grid; grid-template-columns: 58px 1fr; grid-template-rows: auto auto auto; column-gap: 8px;
  padding: 6px 7px; background: var(--cream); border: 2px solid var(--ink); border-radius: 6px;
  box-shadow: inset 0 0 0 2px var(--cream), inset 0 0 0 3px #C2AE86; flex: 0 0 auto; }
.card .thumb { grid-row: 1 / 4; width: 58px; height: 58px; object-fit: contain; align-self: center;
  background: #E6DBC2; border: 1.5px solid var(--ink); border-radius: 4px; padding: 2px; }
.card .thumb.paththumb { background: repeating-linear-gradient(90deg, var(--grass) 0 14px, var(--gravel-edge) 14px 15.5px, var(--gravel) 15.5px 42px, var(--gravel-edge) 42px 43.5px, var(--grass) 43.5px); }
.card h4 { margin: 0; font-family: "Sign"; font-weight: 600; font-size: 16px; line-height: 1.1; letter-spacing: .01em; color: var(--ink); }
.card p { margin: 1px 0 4px; font-size: 11.5px; line-height: 1.25; color: #4A4237; }
.card .row { display: flex; gap: 5px; align-items: center; }
.price { font-family: "Sign"; font-weight: 600; font-size: 15px; color: var(--mustard); background: var(--ink); border-radius: 3px;
  padding: 2px 7px; min-width: 66px; text-align: right; letter-spacing: .02em; }
.buy { flex: 1; height: 26px; border: 2px solid var(--ink); border-radius: 4px; background: var(--terra); color: var(--cream);
  font-family: "Sign"; font-weight: 600; font-size: 15px; letter-spacing: .06em; box-shadow: inset 0 -2px 0 #8F3A1D; }
.buy:active { transform: translateY(1px); box-shadow: none; }
.card.poor { opacity: .55; }
.card.poor .price { color: #E46A55; }
.card.poor .buy { background: #9B8C72; box-shadow: none; }
.card.locked .buy { display: none; }
.card .req { font-family: "Sign"; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--brick); display: flex; align-items: center; gap: 4px; }
.card .req img { width: 18px; height: 18px; }
.card.locked { opacity: .78; }
.card.locked .thumb { filter: grayscale(.7) contrast(.9); }
.card .stamp { position: absolute; right: 8px; top: 6px; width: 30px; height: 30px; transform: rotate(-12deg); opacity: .85; }
.paws { display: inline-flex; gap: 2px; vertical-align: middle; }
.paws img { width: 14px; height: 14px; }
.paws img.empty { opacity: .22; }
.card.wobble, .wobble { animation: wob .42s ease-in-out; }
@keyframes wob { 0%,100% { transform: rotate(0) } 25% { transform: rotate(-1.6deg) } 60% { transform: rotate(1.3deg) } 85% { transform: rotate(-.4deg) } }
.card.sel { outline: 3px solid var(--mustard); outline-offset: -1px; }

/* ---------- map overlays ---------- */
#map { grid-area: map; position: relative; overflow: hidden; background: var(--paper); border-top: 2px solid var(--ink); }
#map canvas { display: block; }
#goal { position: absolute; left: 8px; top: 8px; padding: 5px 10px; font-family: "Sign"; font-weight: 500; font-size: 14px; letter-spacing: .04em;
  pointer-events: none; display: flex; gap: 8px; align-items: center; max-width: calc(100% - 16px); }
#goal b { color: var(--mustard); font-weight: 600; }
#hint { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); padding: 7px 8px 7px 14px; display: none; gap: 10px; align-items: center;
  font-size: 14px; font-weight: 600; max-width: calc(100% - 16px); }
#hint.show { display: flex; }
#hint span { line-height: 1.25; }
#hint button { height: 32px; padding: 0 12px; border: 2px solid var(--ink); border-radius: 4px; background: var(--cream); color: var(--ink);
  font-family: "Sign"; font-weight: 600; font-size: 14px; letter-spacing: .05em; white-space: nowrap; }
#hint button.go { background: var(--terra); color: var(--cream); }
#info { position: absolute; right: 10px; top: 10px; width: 270px; padding: 10px 12px 12px; max-height: calc(100% - 20px); overflow: auto; }
#info.hidden, #modal.hidden { display: none; }
#info h3, #modalBox h3 { margin: 0 0 2px; font-family: "Sign"; font-weight: 600; font-size: 21px; letter-spacing: .02em; text-transform: uppercase; }
#info .kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 13px; margin: 6px 0 8px; font-variant-numeric: tabular-nums; }
#info .kv span:nth-child(odd) { color: #6B6050; }
#info .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.btn { height: 34px; padding: 0 12px; border: 2px solid var(--ink); border-radius: 4px; background: var(--cream); font-family: "Sign"; font-weight: 600; font-size: 15px; letter-spacing: .04em; }
.btn.go { background: var(--terra); color: var(--cream); box-shadow: inset 0 -2px 0 #8F3A1D; }
.btn.go.poor { background: #9B8C72; box-shadow: none; }
.btn .price { font-size: 13px; margin-left: 6px; padding: 1px 5px; min-width: 0; }
.warn { color: var(--brick); font-family: "Sign"; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
#toast { position: absolute; left: 50%; top: 52px; transform: translateX(-50%); pointer-events: none; display: flex; flex-direction: column; gap: 6px; align-items: center; }
#toast div { background: var(--cream); border: 2px solid var(--ink); border-radius: 5px; padding: 5px 12px; font-family: "Sign"; font-size: 15px; letter-spacing: .03em;
  animation: toast 2.6s ease forwards; white-space: nowrap; }
#toast div.bad { color: var(--brick); }
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px) } 10% { opacity: 1; transform: translateY(1px) } 16% { transform: none } 80% { opacity: 1 } 100% { opacity: 0 } }

#modal { position: fixed; inset: 0; background: rgba(42,38,32,.45); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
#modalBox { width: min(440px, 100%); max-height: 100%; overflow: auto; padding: 16px 18px; font-size: 14px; line-height: 1.45; }
#modalBox ul { padding-left: 18px; margin: 8px 0; }
#modalBox li { margin: 3px 0; }
#modalBox .acts { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }
#modalBox .scope { font-size: 12px; color: #6B6050; }
#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--paper); z-index: 30; }
#loading .plate { padding: 14px 22px; display: flex; flex-direction: column; align-items: center; font-family: "Sign"; }
#loading b { font-size: 22px; letter-spacing: .06em; }
#loading.gone { display: none; }


/* ---------- small landscape (phones sideways) ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  :root { --menu-w: 210px; --top-h: 44px; }
  #top { padding: 4px 4px 3px; gap: 4px; }
  #top .plate { padding: 0 7px; gap: 5px; }
  .logo small { display: none; }
  .logo b { font-size: 17px; }
  .logo img { width: 22px; height: 22px; }
  .stat b { font-size: 19px; }
  .money img, .vis img { width: 22px; height: 22px; }
  .flow { font-size: 14px; flex-direction: column; justify-content: center; gap: 0 !important; line-height: 1.05; }
  .welf .thermo { display: none; }
  .gauge small { display: none; }
  .welf .face { width: 22px; height: 22px; }
  .clock b { font-size: 14px; } .clock small { font-size: 10px; }
  .btn-round { min-width: 36px; }
  #tabs { flex-direction: row; flex-wrap: wrap; gap: 3px; }
  .tab { height: 28px; font-size: 13px; padding: 0 14px 0 5px; gap: 4px; flex: 1 1 45%;
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%); }
  .tab img { width: 16px; height: 16px; }
  .card { grid-template-columns: 44px 1fr; padding: 4px 5px; }
  .card .thumb { width: 44px; height: 44px; }
  .card h4 { font-size: 14px; } .card p { font-size: 10.5px; margin-bottom: 3px; }
  .price { font-size: 13px; min-width: 54px; } .buy { height: 23px; font-size: 13px; }
  #info { width: 210px; padding: 6px 9px 8px; } #info h3 { font-size: 16px; }
  #info .kv { font-size: 11px; margin: 3px 0 5px; gap: 0 8px; } #info .btn { height: 27px; font-size: 13px; padding: 0 8px; }
  #hint { font-size: 12px; padding: 4px 6px 4px 10px; bottom: 6px; } #hint button { height: 28px; }
  #goal { font-size: 12px; padding: 3px 8px; }
}
@media (max-width: 900px) and (orientation: landscape) and (min-height: 521px) {
  .logo small { display: none; }
  .clock { display: none !important; }
}

/* ---------- portrait: ledger becomes a bottom drawer ---------- */
@media (orientation: portrait), (max-width: 620px) {
  :root { --top-h: auto; }
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top" "map" "menu"; }
  #top { flex-wrap: wrap; padding: 5px; gap: 4px; }
  #top .plate { height: 38px; padding: 0 7px; gap: 5px; }
  .logo { flex: 1 1 auto; } .logo small { display: none; } .logo b { font-size: 17px; } .logo img { width: 22px; height: 22px; }
  .stat b { font-size: 19px; }
  .money { flex: 1 1 auto; }
  .money img, .vis img { width: 22px; height: 22px; }
  .flow { font-size: 13px; flex-direction: column; justify-content: center; gap: 0 !important; line-height: 1.05; }
  .welf { flex: 1 1 120px; max-width: none; } .welf .thermo { display: none; } .gauge small { font-size: 9px; }
  .welf .face { width: 22px; height: 22px; }
  .clock b { font-size: 13px; } .clock small { font-size: 10px; }
  .btn-round { min-width: 38px; }
  #menu { border-right: 0; border-top: 2px solid var(--ink); padding: 5px 5px calc(6px + env(safe-area-inset-bottom)); gap: 5px; }
  #tabs { flex-direction: row; gap: 3px; overflow-x: auto; scrollbar-width: none; }
  .tab { height: 32px; font-size: 14px; padding: 0 15px 0 6px; gap: 4px; flex: 1 0 auto;
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%); }
  .tab img { width: 18px; height: 18px; }
  #cards { flex-direction: row; overflow-x: auto; overflow-y: hidden; height: 132px; flex: 0 0 auto; touch-action: pan-x; gap: 5px; padding-bottom: 2px; }
  .card { width: 212px; grid-template-columns: 48px 1fr; align-content: center; }
  .card .thumb { width: 48px; height: 48px; }
  .section { writing-mode: vertical-rl; transform: rotate(180deg); padding: 0 2px; font-size: 11px; text-align: center; }
  .note { width: 170px; flex: 0 0 auto; align-self: center; }
  #info { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; }
  #goal { font-size: 12px; padding: 4px 8px; }
  #hint { bottom: 8px; font-size: 13px; width: calc(100% - 16px); }
}

/* narrow landscape phones: give the badge and the money room, drop what can wait */
@media (max-width: 760px) and (orientation: landscape) {
  .logo b { font-size: 15px; letter-spacing: 0; }
  .logo img { width: 18px; height: 18px; }
  #top .plate { padding: 0 5px; }
  .clock { display: none !important; }
}
@media (max-width: 600px) and (orientation: landscape) {
  .vis { display: none !important; }
}
