:root {
  --panel: rgba(255, 251, 242, 0.94);
  --panel-solid: #fffbf2;
  --ink: #2f3a3f;
  --ink-soft: #66737a;
  --line: rgba(47, 58, 63, 0.12);
  --accent: #3f9b6a;
  --accent-dark: #2f7d54;
  --accent-soft: #dff1e6;
  --gold: #f2b632;
  --warn: #d9534f;
  --shadow: 0 6px 24px rgba(30, 50, 60, 0.18), 0 1px 3px rgba(30, 50, 60, 0.12);
  --radius: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #8fc7e8; font-family: Nunito, 'Trebuchet MS', system-ui, sans-serif; color: var(--ink); -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
#game { position: fixed; inset: 0; }
#game canvas { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
.hidden { display: none !important; }
button { font-family: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic .fill { fill: currentColor; stroke: none; }

/* ---------- top bar ---------- */
#topLeft { position: fixed; top: 12px; left: 12px; display: flex; gap: 8px; flex-wrap: wrap; max-width: 60vw; }
.pill { display: flex; align-items: center; gap: 7px; background: var(--panel); padding: 7px 14px 7px 9px; border-radius: 999px; box-shadow: var(--shadow); font-size: 17px; font-weight: 800; }
.coin { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffe28a, #f2b632 60%, #c98a12); box-shadow: inset 0 0 0 2px #e0a21f; position: relative; }
.coin::after { content: ''; position: absolute; inset: 6px; border-radius: 50%; border: 2px solid rgba(160, 100, 10, 0.45); }
#coinPill.bump { animation: bump 0.35s ease; }
@keyframes bump { 40% { transform: scale(1.12); } }
.clockic { width: 18px; height: 18px; border-radius: 50%; background: #ffc94a; box-shadow: 0 0 0 3px rgba(255, 201, 74, 0.3); transition: background 0.5s; }
.clockic.moon { background: #dfe6ff; box-shadow: inset -5px -2px 0 0 #8d9bd6, 0 0 0 3px rgba(150, 170, 255, 0.25); }
#topRight { position: fixed; top: 12px; right: 12px; display: flex; gap: 8px; align-items: center; }
.round { width: 42px; height: 42px; border-radius: 50%; background: var(--panel); box-shadow: var(--shadow); display: grid; place-items: center; transition: transform 0.15s; }
.round:hover { transform: translateY(-1px); }
.seg { display: flex; background: var(--panel); border-radius: 999px; box-shadow: var(--shadow); padding: 4px; }
.seg button { width: 36px; height: 34px; border-radius: 999px; display: grid; place-items: center; color: var(--ink-soft); }
.seg button.on { background: var(--accent); color: #fff; }

/* ---------- goal ---------- */
#goal { position: fixed; left: 12px; top: 64px; max-width: 290px; padding: 10px 14px; font-size: 14px; font-weight: 700; line-height: 1.35; transition: opacity 0.3s; }
.goalHead { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent-dark); font-weight: 900; margin-bottom: 2px; }

/* ---------- train list ---------- */
#trainList { position: fixed; right: 12px; top: 64px; width: 230px; overflow: hidden; }
#trainListHead { width: 100%; display: flex; align-items: center; gap: 8px; padding: 10px 14px; font-weight: 800; font-size: 14px; }
#trainListHead span { flex: 1; text-align: left; }
#trainListHead b { background: var(--accent-soft); color: var(--accent-dark); border-radius: 999px; padding: 1px 9px; font-size: 13px; }
#trainList.collapsed .chev { transform: rotate(-90deg); }
#trainList.collapsed #trainListBody { display: none; }
#trainListBody { max-height: 42vh; overflow-y: auto; padding: 0 6px 6px; }
.trow { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 8px; border-radius: 10px; text-align: left; }
.trow:hover, .trow.sel { background: rgba(63, 155, 106, 0.12); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.15); }
.trow .tn { font-weight: 800; font-size: 14px; }
.trow .ts { font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }

/* ---------- toolbar ---------- */
#toolbar { position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 6px; background: var(--panel); padding: 7px; border-radius: 22px; box-shadow: var(--shadow); }
.tool { width: 66px; height: 62px; border-radius: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 12px; font-weight: 800; color: var(--ink-soft); transition: background 0.15s, color 0.15s, transform 0.15s; }
.tool svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { background: rgba(0, 0, 0, 0.05); color: var(--ink); }
.tool.on { background: var(--accent); color: #fff; transform: translateY(-3px); box-shadow: 0 4px 12px rgba(63, 155, 106, 0.4); }
.tool[data-tool="bulldoze"].on { background: #d9774f; box-shadow: 0 4px 12px rgba(217, 119, 79, 0.4); }
#toolHint { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(40, 50, 55, 0.78); color: #fff; padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; pointer-events: none; white-space: nowrap; transition: opacity 0.25s; }
#toolHint:empty { opacity: 0; }

/* ---------- drawers ---------- */
.drawer { position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(760px, calc(100vw - 24px)); padding: 12px 14px 14px; animation: rise 0.2s ease; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }
.drawerHead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 17px; }
.x { font-size: 24px; line-height: 1; width: 32px; height: 32px; border-radius: 50%; color: var(--ink-soft); }
.x:hover { background: rgba(0, 0, 0, 0.06); }
.cards { padding: 3px; display: grid; grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 10px; max-height: 46vh; overflow-y: auto; }
.cards.small { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.tcard { background: #fff; border-radius: 13px; padding: 10px; display: flex; flex-direction: column; gap: 5px; text-align: left; box-shadow: 0 0 0 1px var(--line); transition: transform 0.15s, box-shadow 0.15s; }
.tcard:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 0 0 2px var(--accent), 0 6px 14px rgba(0, 0, 0, 0.08); }
.tcard:disabled { opacity: 0.55; cursor: default; }
.tcard.on { box-shadow: 0 0 0 3px var(--accent); }
.tcard .thumb { height: 56px; border-radius: 9px; display: grid; place-items: center; overflow: hidden; }
.tcard .thumb canvas { width: 100%; height: 100%; }
.tcard .nm { font-weight: 900; font-size: 14px; }
.tcard .bl { font-size: 12px; color: var(--ink-soft); line-height: 1.3; min-height: 31px; }
.tcard .price { display: flex; align-items: center; gap: 5px; font-weight: 900; font-size: 14px; }
.tcard .price .coin { width: 16px; height: 16px; }
.tcard .price .coin::after { inset: 4px; border-width: 1.5px; }
.bars { display: flex; gap: 6px; font-size: 11px; color: var(--ink-soft); align-items: center; }
.bar { flex: 1; height: 5px; background: #eee; border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.note { margin: 8px 2px 0; font-size: 12px; color: var(--ink-soft); }
.owned { font-size: 11px; font-weight: 900; color: var(--accent-dark); background: var(--accent-soft); border-radius: 999px; padding: 1px 7px; align-self: flex-start; }

/* ---------- side panels ---------- */
.side { position: fixed; right: 12px; bottom: calc(100px + env(safe-area-inset-bottom)); width: 290px; padding: 14px; animation: slidein 0.2s ease; }
@keyframes slidein { from { opacity: 0; transform: translateX(14px); } }
.side h3 { margin: 0; font-size: 19px; display: flex; align-items: center; gap: 8px; }
.side h3 input { font: inherit; border: 0; background: transparent; width: 100%; padding: 2px 4px; border-radius: 6px; color: inherit; }
.side h3 input:focus { outline: 2px solid var(--accent); background: #fff; }
.side .sub { color: var(--ink-soft); font-size: 13px; font-weight: 700; margin: 2px 0 10px 4px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.stat { background: #fff; border-radius: 10px; padding: 6px 9px; box-shadow: 0 0 0 1px var(--line); }
.stat small { display: block; font-size: 11px; color: var(--ink-soft); font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; }
.stat b { font-size: 16px; }
.row { display: flex; gap: 6px; margin-top: 6px; }
.btn { flex: 1; background: #fff; box-shadow: 0 0 0 1px var(--line); border-radius: 10px; padding: 8px 6px; font-weight: 800; font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 5px; transition: background 0.15s; }
.btn:hover:not(:disabled) { background: #f3f6f4; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; box-shadow: none; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--warn); }
.btn .ic { width: 17px; height: 17px; }
.carRow { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 10px; padding: 6px 8px; box-shadow: 0 0 0 1px var(--line); }
.carRow span { flex: 1; font-weight: 800; font-size: 14px; }
.carRow .mini { width: 32px; height: 32px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-dark); font-size: 20px; font-weight: 900; }
.carRow .mini:disabled { opacity: 0.4; }
.carRow small { color: var(--ink-soft); font-weight: 700; }
.closeX { position: absolute; top: 8px; right: 8px; }

#camBar { white-space: nowrap; position: fixed; top: 64px; left: 50%; transform: translateX(-50%); background: rgba(40, 50, 55, 0.8); color: #fff; border-radius: 999px; padding: 6px 6px 6px 16px; display: flex; gap: 10px; align-items: center; font-weight: 800; font-size: 14px; }
#camBar button { background: rgba(255, 255, 255, 0.18); color: #fff; padding: 6px 12px; border-radius: 999px; font-weight: 800; font-size: 13px; }

/* ---------- toasts & floaters ---------- */
#toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; z-index: 5; }
.toast { background: var(--panel-solid); border-radius: 14px; box-shadow: var(--shadow); padding: 10px 16px; display: flex; align-items: center; gap: 12px; animation: toastIn 0.35s cubic-bezier(.2, 1.4, .4, 1); max-width: min(420px, 90vw); }
.toast.out { animation: toastOut 0.4s ease forwards; }
.toast .tic { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--gold); color: #fff; flex: none; }
.toast.goal .tic { background: var(--accent); }
.toast.info .tic { background: #7a8b94; }
.toast b { display: block; font-size: 15px; }
.toast small { color: var(--ink-soft); font-weight: 700; font-size: 13px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px) scale(0.9); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }
#floaters { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.floater { position: absolute; font-weight: 900; font-size: 20px; color: #fff; text-shadow: 0 2px 0 #b07d10, 0 3px 8px rgba(0, 0, 0, 0.3); transform: translate(-50%, -50%); white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.floater .coin { width: 18px; height: 18px; }

/* ---------- modal ---------- */
#modal { position: fixed; inset: 0; background: rgba(30, 45, 55, 0.35); display: grid; place-items: center; z-index: 10; animation: fade 0.2s; }
@keyframes fade { from { opacity: 0; } }
.modalCard { width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 40px); overflow-y: auto; padding: 20px 22px; position: relative; background: var(--panel-solid); }
.modalCard h2 { margin: 0 0 12px; font-size: 22px; }
.modalCard h4 { margin: 16px 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent-dark); }
.modalCard p, .modalCard li { font-size: 15px; line-height: 1.5; }
.modalCard ul { padding-left: 20px; margin: 6px 0; }
.kbd { display: inline-block; background: #fff; border-radius: 6px; padding: 0 6px; box-shadow: 0 0 0 1px var(--line), 0 2px 0 var(--line); font-size: 13px; font-weight: 800; }
.setRow { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-weight: 700; }
.setRow label { flex: 1; }
.setRow input[type=range] { width: 150px; accent-color: var(--accent); }
.switch { position: relative; width: 44px; height: 26px; border-radius: 999px; background: #cfd6d3; transition: background 0.2s; flex: none; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: left 0.2s; }
.switch.on { background: var(--accent); }
.switch.on::after { left: 21px; }
.achList { display: grid; gap: 8px; }
.ach { display: flex; gap: 12px; align-items: center; background: #fff; border-radius: 12px; padding: 9px 12px; box-shadow: 0 0 0 1px var(--line); }
.ach .medal { width: 34px; height: 34px; border-radius: 50%; background: #e7ebe9; display: grid; place-items: center; color: #aab4b0; flex: none; }
.ach.got .medal { background: var(--gold); color: #fff; }
.ach b { display: block; font-size: 15px; }
.ach small { color: var(--ink-soft); font-weight: 700; }
.ach .rw { margin-left: auto; font-weight: 900; font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.modalBtns { display: flex; gap: 8px; margin-top: 16px; }

/* ---------- title ---------- */
#title, #webglError { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(180deg, rgba(143, 199, 232, 0.55), rgba(200, 230, 200, 0.55)); z-index: 20; transition: opacity 0.6s; padding: 16px; }
#title.fade { opacity: 0; pointer-events: none; }
.titleCard { background: var(--panel-solid); border-radius: 26px; box-shadow: var(--shadow); padding: 28px 30px; text-align: center; max-width: 430px; animation: rise2 0.6s cubic-bezier(.2, 1.2, .4, 1); }
@keyframes rise2 { from { opacity: 0; transform: translateY(20px); } }
.logo svg { width: 170px; height: 85px; }
.titleCard h1 { margin: 2px 0 6px; font-size: 40px; font-weight: 900; letter-spacing: -0.02em; color: #2d5a43; }
.titleCard p { color: var(--ink-soft); font-size: 16px; font-weight: 700; line-height: 1.45; margin: 0 0 18px; }
.titleBtns { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.big { background: var(--accent); color: #fff; font-size: 20px; font-weight: 900; padding: 13px 54px; border-radius: 999px; box-shadow: 0 5px 0 var(--accent-dark), 0 8px 18px rgba(63, 155, 106, 0.35); transition: transform 0.1s, box-shadow 0.1s; }
.big:hover { transform: translateY(-1px); }
.big:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent-dark); }
.ghost { color: var(--ink-soft); font-weight: 800; font-size: 14px; padding: 6px 12px; border-radius: 999px; }
.ghost:hover { background: rgba(0, 0, 0, 0.05); }
.tiny { font-size: 12px !important; margin: 14px 0 0 !important; }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .tool { width: 50px; height: 54px; font-size: 10px; }
  .tool svg { width: 22px; height: 22px; }
  #toolbar { gap: 2px; padding: 5px; border-radius: 18px; }
  #toolHint { bottom: calc(80px + env(safe-area-inset-bottom)); font-size: 12px; white-space: normal; text-align: center; max-width: 92vw; }
  .drawer { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .side { left: 12px; right: 12px; width: auto; bottom: calc(80px + env(safe-area-inset-bottom)); max-height: 55vh; overflow-y: auto; }
  #goal { display: none; }
  #trainList { top: auto; bottom: auto; top: 60px; width: 190px; }
  .pill { font-size: 14px; padding: 5px 11px 5px 7px; }
  .round { width: 36px; height: 36px; }
  .seg button { width: 30px; height: 28px; }
  #topLeft { max-width: 50vw; }
  #topLeft .pill:nth-child(2) { display: none; }
  #camBar { top: 112px; font-size: 13px; }
}
@media (max-width: 420px) {
  #achBtn { display: none; }
}

/* ---------- seasons, levels, cargo ---------- */
.seasonic { width: 18px; height: 18px; border-radius: 50%; position: relative; }
.seasonic.s0 { background: radial-gradient(circle, #ffd1e3 30%, #f49ac1 32%, #f49ac1 60%, transparent 62%); }
.seasonic.s1 { background: radial-gradient(circle, #7cc26b 55%, transparent 57%); box-shadow: inset 0 -4px 0 #4f9a44; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); }
.seasonic.s2 { background: #e0873a; border-radius: 50% 0 50% 0; box-shadow: inset 0 0 0 2px #b55f22; }
.seasonic.s3 { background: radial-gradient(circle, #fff 40%, #cfe3f5 42%); box-shadow: 0 0 0 2px #b9d3ea; }
.lvl { display: flex; align-items: center; gap: 8px; margin: -4px 0 10px 4px; font-size: 12px; color: var(--ink-soft); font-weight: 800; }
.stars { display: flex; gap: 2px; }
.stars i { width: 12px; height: 12px; background: #d9dfdc; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.stars i.on { background: var(--gold); }
.xpbar { width: 54px; height: 6px; background: #e3e8e5; border-radius: 3px; overflow: hidden; display: inline-block; }
.xpbar.wide { width: 120px; }
.xpbar b { display: block; height: 100%; background: var(--gold); border-radius: 3px; }
.kindSeg { margin-bottom: 8px; box-shadow: 0 0 0 1px var(--line); }
.kindSeg button { flex: 1; width: auto; font-weight: 800; font-size: 13px; }
.load { margin-top: 6px; background: #fff; border-radius: 10px; padding: 6px 8px; box-shadow: 0 0 0 1px var(--line); display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 12px; }
.load > small { font-weight: 800; color: var(--ink-soft); margin-right: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #f3f1ea; border-radius: 999px; padding: 1px 8px 1px 4px; font-size: 12px; font-weight: 800; margin: 1px 2px 1px 0; }
.chip i { width: 10px; height: 10px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); }
.chip b { color: var(--accent-dark); }
.empty { color: var(--ink-soft); font-weight: 700; font-size: 12px; }
.kv { display: flex; gap: 8px; align-items: baseline; padding: 5px 4px; border-top: 1px solid var(--line); font-size: 13px; font-weight: 700; }
.kv > small { width: 92px; flex: none; color: var(--ink-soft); font-weight: 800; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.kv > span { flex: 1; min-width: 0; }
.kind { font-size: 11px; font-weight: 800; color: #8a6d2b; }
#buildTabs button { width: auto; padding: 0 14px; font-weight: 800; font-size: 14px; }
.journal { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
.journal h4 { margin-top: 8px !important; }
.jrow { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 14px; font-weight: 700; }
.jrow b { font-variant-numeric: tabular-nums; }
.modalCard .sub { color: var(--ink-soft); font-weight: 700; margin: -6px 0 6px; }
#photoBar { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 8px; align-items: center; background: var(--panel); padding: 8px; border-radius: 16px; box-shadow: var(--shadow); z-index: 6; }
#photoBar .btn { flex: none; padding: 8px 14px; }
#photoBar .tiny { margin: 0 6px !important; color: var(--ink-soft); font-weight: 700; }
#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 30; }
#flash.go { animation: flash 0.5s ease; }
@keyframes flash { 0% { opacity: 0.85; } 100% { opacity: 0; } }
.floater small { font-size: 14px; text-shadow: 0 1px 0 #3a6a50, 0 2px 6px rgba(0, 0, 0, 0.35); }
@media (max-width: 720px) {
  .tool { width: 44px; height: 52px; font-size: 9.5px; }
  .tool svg { width: 21px; height: 21px; }
  #topLeft .pill:nth-child(4) { display: none; }
  .journal { grid-template-columns: 1fr; }
  #photoBar .tiny { display: none; }
}
@media (max-width: 420px) {
  #journalBtn, #photoBtn { display: none; }
  #topLeft .pill:nth-child(3) { display: none; }
  .tool { width: 41px; }
}
