/* Driftline: vintage travel / rally road-book. Cream paper, ink, postbox red, airmail blue, kraft. */
:root {
  --paper: #efe4c8; --paper2: #f7f0de; --ink: #24262b; --red: #c8442b; --blue: #2f6fa8; --kraft: #c69a62;
  --muted: #6d6658; --line: rgba(36, 38, 43, 0.18);
  --slab: 'Alfa Slab One', Georgia, serif; --ui: 'Barlow Condensed', 'Arial Narrow', sans-serif; --mono: 'IBM Plex Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #b9c9cf; color: var(--ink); font-family: var(--ui); font-size: 17px; }
#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--ink); background: var(--paper2); border: 2px solid var(--ink); border-radius: 4px; padding: 6px 10px; }
kbd { font-family: var(--mono); font-size: 0.78em; background: var(--paper2); border: 1.5px solid var(--ink); border-bottom-width: 3px; border-radius: 4px; padding: 1px 6px; white-space: nowrap; }
.muted { color: var(--muted); }
.slab { font-family: var(--slab); font-weight: 400; letter-spacing: 0.01em; margin: 0; }
h3 { font-family: var(--slab); font-weight: 400; font-size: 1.15rem; margin: 0 0 10px; }
.paper-tex { background-color: var(--paper); }

/* ---------- panel / sheets ---------- */
#panel { position: fixed; inset: 0; overflow-y: auto; z-index: 5; }
#panel:not(.screen-title) { background: rgba(36, 38, 43, 0.28); }
.sheet {
  position: relative; max-width: 1180px; margin: 28px auto 40px; padding: 26px 30px 30px;
  background: var(--paper); border: 2px solid var(--ink); box-shadow: 8px 8px 0 rgba(36, 38, 43, 0.35);
  background-image: radial-gradient(rgba(36, 38, 43, 0.05) 1px, transparent 1px); background-size: 6px 6px;
}
.sheet.narrow { max-width: 760px; }
.sheet > header { display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 3px double var(--ink); padding-bottom: 14px; margin-bottom: 18px; }
.sheet > header h2 { font-size: 2.2rem; }
.card { background: var(--paper2); border: 2px solid var(--ink); border-radius: 4px; padding: 16px 18px; margin-bottom: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.btns { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 18px; }

/* luggage-tag buttons */
.tag {
  position: relative; display: inline-flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 1px;
  background: var(--kraft); border: 2px solid var(--ink); padding: 9px 20px 9px 34px; min-height: 44px;
  clip-path: polygon(14px 0, 100% 0, 100% 100%, 14px 100%, 0 calc(100% - 14px), 0 14px);
  font-weight: 700; font-size: 1.05rem; text-transform: uppercase; letter-spacing: 0.04em; transition: transform 0.12s, background 0.12s;
}
.tag::before { content: ''; position: absolute; left: 12px; top: 50%; width: 10px; height: 10px; margin-top: -5px; border-radius: 50%; background: var(--paper); border: 2px solid var(--ink); }
.tag:hover { transform: translateX(4px) rotate(-0.6deg); background: #d4a96f; }
.tag:active { transform: translateX(2px) scale(0.98); }
.tag small { font-weight: 500; font-size: 0.82rem; text-transform: none; letter-spacing: 0; color: rgba(36, 38, 43, 0.75); }
.tag.go { background: var(--red); color: var(--paper2); }
.tag.go:hover { background: #d9553a; }
.tag.go small { color: rgba(247, 240, 222, 0.8); }
.tag.go::before { background: var(--paper2); }
.tag.big { font-size: 1.3rem; padding: 12px 26px 12px 38px; }
.tag.back { background: var(--paper2); }
.link { background: none; border: 0; padding: 0; text-decoration: underline; color: var(--blue); font-weight: 600; }

/* segmented choices */
.seg { display: inline-flex; border: 2px solid var(--ink); border-radius: 4px; overflow: hidden; background: var(--paper2); }
.seg button { border: 0; border-right: 2px solid var(--ink); background: none; padding: 7px 14px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.seg button:last-child { border-right: 0; }
.seg button small { font-weight: 500; text-transform: none; font-size: 0.75rem; color: var(--muted); letter-spacing: 0; }
.seg button.on { background: var(--ink); color: var(--paper2); }
.seg button.on small { color: rgba(247, 240, 222, 0.7); }

/* ---------- title ---------- */
.screen-title { background: linear-gradient(90deg, rgba(239, 228, 200, 0.97) 0, rgba(239, 228, 200, 0.94) 470px, rgba(239, 228, 200, 0) 760px); }
.title-wrap { width: min(520px, 100%); min-height: 100%; padding: 46px 40px 30px; display: flex; flex-direction: column; gap: 26px; }
.logo { border: 3px solid var(--ink); padding: 16px 20px 14px; background: var(--paper2); box-shadow: 6px 6px 0 var(--red); transform: rotate(-1.2deg); }
.logo h1 { font-family: var(--slab); font-weight: 400; font-size: 4.2rem; line-height: 0.95; margin: 4px 0; letter-spacing: 0.02em; }
.logo-sub { font-weight: 700; text-transform: uppercase; letter-spacing: 0.18em; font-size: 0.85rem; color: var(--red); }
.logo-route { display: block; font-size: 0.82rem; color: var(--muted); letter-spacing: 0.04em; border-top: 2px dashed var(--line); padding-top: 6px; }
.tags { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.tags .tag { min-width: 300px; }
.keys { font-size: 0.85rem; color: var(--muted); line-height: 2; margin-top: auto; }

/* ---------- postcards ---------- */
.postcard { position: relative; display: flex; gap: 10px; align-items: center; background: #fbf6e8; border: 1.5px solid var(--ink); padding: 8px 10px; text-align: left; min-width: 0; }
.postcard .mini { width: 92px; height: 64px; flex: none; background: repeating-linear-gradient(0deg, transparent 0 11px, rgba(47, 111, 168, 0.12) 11px 12px); }
.pc-txt { display: flex; flex-direction: column; min-width: 0; }
.pc-txt b { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-txt small { color: var(--muted); font-size: 0.82rem; }
.pc-txt .rec { color: var(--blue); font-weight: 600; }
.pc-stamp { position: absolute; top: 6px; right: 6px; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; color: var(--paper2); background: var(--stamp); padding: 3px 5px; outline: 2px dotted var(--stamp); outline-offset: 1px; }
.cups { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 16px; margin-top: 16px; }
.cup { display: flex; flex-direction: column; gap: 10px; }
.cup-head { display: flex; justify-content: space-between; align-items: center; }
.cup-head h3 { margin: 0; }
.cup-tracks { display: grid; gap: 6px; }
.medal { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; border: 2px solid var(--ink); border-radius: 999px; padding: 2px 10px; background: var(--paper); }
.medal.m1 { background: #e8c23a; } .medal.m2 { background: #c9ccd1; } .medal.m3 { background: #c98a4a; }
.cup .go { align-self: flex-start; margin-top: auto; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; margin-bottom: 18px; }
.pick { background: none; border: 0; padding: 0; text-align: left; }
.pick .postcard { transition: transform 0.12s, box-shadow 0.12s; }
.pick:hover .postcard { transform: translateY(-2px); }
.pick.on .postcard { box-shadow: 0 0 0 3px var(--red), 4px 4px 0 var(--ink); }

/* daily + boards */
.daily { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; }
.daily-card .postcard { margin-bottom: 12px; }
.daily-card .postcard .mini { width: 200px; height: 130px; }
.lb { list-style: none; padding: 0; margin: 0; max-height: 420px; overflow-y: auto; }
.lb li { display: flex; align-items: center; gap: 8px; padding: 5px 4px; border-bottom: 1px dashed var(--line); }
.lb li span { width: 24px; font-weight: 700; color: var(--muted); }
.lb li i, .sw { display: inline-block; width: 14px; height: 14px; border: 1.5px solid var(--ink); border-radius: 3px; vertical-align: -2px; margin-right: 6px; flex: none; }
.lb li b { margin-left: auto; font-family: var(--mono); font-weight: 500; }
.lb li.me { background: rgba(200, 68, 43, 0.12); }
.board.small .lb { max-height: 220px; }

/* online */
.code { width: 120px; text-transform: uppercase; font-family: var(--mono); font-size: 1.4rem; letter-spacing: 0.2em; margin-right: 10px; }
.code-big { font-family: var(--mono); letter-spacing: 0.15em; background: var(--ink); color: var(--paper2); padding: 0 10px; }
.plist { list-style: none; margin: 0; padding: 0; }
.plist li { padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 1.1rem; }
.plist small { font-weight: 700; color: var(--red); text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.08em; }
.form label { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; font-weight: 600; flex-wrap: wrap; }
.form label input[type=range] { flex: 1; min-width: 160px; accent-color: var(--red); }
.form select, .form input:not([type=range]) { flex: 1; min-width: 200px; }
.ctl { width: 100%; border-collapse: collapse; }
.ctl td { padding: 6px 4px; border-bottom: 1px dashed var(--line); }
.ctl td:first-child { font-weight: 700; }

/* results */
.results { width: 100%; border-collapse: collapse; font-size: 1.05rem; }
.results th { text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); border-bottom: 2px solid var(--ink); padding: 6px; }
.results td { padding: 7px 6px; border-bottom: 1px dashed var(--line); }
.results td:nth-child(3), .results td:nth-child(4) { font-family: var(--mono); font-size: 0.95rem; }
.results tr.me td { background: rgba(200, 68, 43, 0.13); font-weight: 700; }
.stampmark { font-family: var(--slab); color: var(--red); border: 3px double var(--red); padding: 4px 12px; transform: rotate(4deg); text-transform: uppercase; font-size: 0.95rem; }
.trophy { width: 170px; height: 170px; margin: 6px auto 20px; border-radius: 50%; border: 4px double var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--paper2); transform: rotate(-6deg); box-shadow: 5px 5px 0 rgba(36, 38, 43, 0.3); }
.trophy b { font-family: var(--slab); font-size: 3rem; font-weight: 400; line-height: 1; }
.trophy small { font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.trophy.m1 { background: #e8c23a; } .trophy.m2 { background: #c9ccd1; } .trophy.m3 { background: #c98a4a; }

/* garage */
.garage { display: grid; grid-template-columns: 1fr 1.1fr; gap: 16px; }
.gview { display: flex; flex-direction: column; align-items: center; }
.gview canvas { display: block; max-width: 100%; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { background: var(--paper); border: 2px solid var(--ink); border-bottom-width: 4px; padding: 5px 14px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.tabs button.on { background: var(--ink); color: var(--paper2); }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; max-height: 360px; overflow-y: auto; padding: 2px; }
.sw-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; background: #fbf6e8; border: 2px solid var(--ink); border-radius: 4px; padding: 8px; text-align: left; font-weight: 600; }
.sw-btn i { width: 100%; height: 26px; border: 1.5px solid var(--ink); border-radius: 3px; }
.sw-btn.on { box-shadow: 0 0 0 3px var(--red); }
.sw-btn.locked { opacity: 0.5; cursor: not-allowed; background: repeating-linear-gradient(135deg, #f3ead3 0 6px, #ebe0c3 6px 12px); }
.sw-btn small { font-size: 0.72rem; color: var(--muted); font-weight: 500; line-height: 1.2; }
.passport .stamps { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-bottom: 18px; }
.pstamp { border: 2px dashed var(--line); border-radius: 6px; padding: 10px; color: var(--muted); }
.pstamp b { display: block; font-size: 0.95rem; }
.pstamp small { font-size: 0.78rem; }
.pstamp.got { border: 3px double var(--red); color: var(--ink); transform: rotate(-1deg); background: rgba(200, 68, 43, 0.07); }
.recs { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 4px 16px; }
.rec-row { display: flex; gap: 10px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.rec-row b { flex: 1; } .rec-row span { font-family: var(--mono); font-size: 0.85rem; color: var(--muted); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 4; }
.h-left { position: absolute; left: 22px; top: 18px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.postmark { width: 112px; height: 112px; border-radius: 50%; background: var(--paper2); border: 4px double var(--ink); display: flex; align-items: center; justify-content: center; font-family: var(--slab); font-size: 3.6rem; line-height: 1; color: var(--red); transform: rotate(-8deg); box-shadow: 4px 4px 0 rgba(36, 38, 43, 0.4); }
.postmark sup { font-size: 1.2rem; color: var(--ink); margin-left: 2px; }
#h-board { list-style: none; margin: 0; padding: 6px 8px; background: rgba(247, 240, 222, 0.92); border: 2px solid var(--ink); min-width: 170px; font-size: 0.95rem; }
#h-board li { display: flex; align-items: center; gap: 6px; padding: 1px 2px; white-space: nowrap; }
#h-board li span { width: 16px; font-weight: 700; color: var(--muted); }
#h-board li i { width: 11px; height: 11px; border: 1.5px solid var(--ink); border-radius: 2px; }
#h-board li.me { background: var(--ink); color: var(--paper2); }
#h-board li.me span { color: var(--paper2); }
#h-board li.hu { color: var(--blue); font-weight: 700; }
.h-right { position: absolute; right: 22px; top: 18px; }
.roadbook { background: var(--paper2); border: 2px solid var(--ink); box-shadow: 4px 4px 0 rgba(36, 38, 43, 0.4); padding: 8px 16px; text-align: right; min-width: 190px; }
#h-lap { font-weight: 700; letter-spacing: 0.08em; font-size: 1rem; }
#h-lap b { font-family: var(--slab); font-weight: 400; font-size: 1.9rem; color: var(--red); }
#h-time { font-family: var(--mono); font-size: 1.5rem; font-weight: 600; }
#h-route { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); font-weight: 700; text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.85rem; background: rgba(247, 240, 222, 0.85); border: 2px solid var(--ink); padding: 3px 12px; }
.h-item { position: absolute; left: 22px; bottom: 22px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pstamp-slot {
  position: relative; width: 104px; height: 104px; background: var(--paper2); padding: 12px; display: flex; align-items: center; justify-content: center;
  -webkit-mask: radial-gradient(circle 5px at 50% 0, transparent 98%, #000) 0 0 / 16px 51% repeat-x, radial-gradient(circle 5px at 50% 100%, transparent 98%, #000) 0 100% / 16px 51% repeat-x;
  mask: radial-gradient(circle 5px at 50% 0, transparent 98%, #000) 0 0 / 16px 51% repeat-x, radial-gradient(circle 5px at 50% 100%, transparent 98%, #000) 0 100% / 16px 51% repeat-x;
  filter: drop-shadow(3px 3px 0 rgba(36, 38, 43, 0.45));
}
.pstamp-slot::before { content: ''; position: absolute; inset: 9px; border: 2px solid var(--ink); }
.pstamp-slot svg { width: 64px; height: 64px; position: relative; }
.pstamp-slot i { position: absolute; right: 12px; bottom: 9px; font-style: normal; font-family: var(--slab); font-size: 1.2rem; }
#h-itemname { font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.82rem; background: var(--ink); color: var(--paper2); padding: 2px 8px; min-height: 1em; }
#h-itemname:empty { display: none; }
#h-map { position: absolute; right: 22px; bottom: 22px; width: 180px; height: 180px; background: rgba(247, 240, 222, 0.88); border: 2px solid var(--ink); box-shadow: 4px 4px 0 rgba(36, 38, 43, 0.4); }
#h-drift { position: absolute; bottom: 34px; left: 50%; transform: translateX(-50%); font-weight: 700; letter-spacing: 0.2em; font-size: 1.1rem; }
#h-drift span { background: var(--paper2); border: 2px solid var(--ink); padding: 3px 12px; }
#h-drift .t1 { background: #ffd04a; } #h-drift .t2 { background: #ff7b2e; } #h-drift .t3 { background: var(--ink); color: var(--paper2); }
#h-count { position: absolute; top: 32%; left: 50%; transform: translate(-50%, -50%); font-family: var(--slab); font-size: 9rem; color: var(--paper2); -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; text-shadow: 8px 8px 0 var(--red); }
#h-count.pop { animation: pop 0.45s ease-out; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(1.6); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
#h-flash { position: absolute; top: 24%; left: 50%; transform: translate(-50%, -50%) rotate(-3deg); font-family: var(--slab); font-size: 2.6rem; color: var(--red); background: var(--paper2); border: 4px double var(--red); padding: 4px 22px; opacity: 0; transition: opacity 0.25s; }
#h-flash:empty { display: none; }
#h-flash.show { opacity: 1; }
#h-flash.big { font-size: 4rem; }
#h-wrong { position: absolute; top: 45%; left: 50%; transform: translate(-50%, -50%); font-family: var(--slab); font-size: 2.8rem; color: var(--paper2); background: var(--red); border: 3px solid var(--ink); padding: 4px 22px; }
#h-wrong:empty { display: none; }
#h-pause { position: absolute; inset: 0; background: rgba(36, 38, 43, 0.4); display: flex; align-items: center; justify-content: center; pointer-events: auto; }
.pause { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; min-width: 300px; padding: 24px 28px; box-shadow: 8px 8px 0 rgba(36, 38, 43, 0.4); }
.pause .tag { min-width: 240px; }

/* ---------- workshop ---------- */
#workshop { position: fixed; inset: 0; z-index: 6; display: grid; grid-template-columns: 1fr 360px; background: var(--paper); }
#workshop[hidden] { display: none; }
.ed-map { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
.ed-side { margin: 0; border-radius: 0; border-width: 0 0 0 3px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.ed-side h2 { font-size: 1.7rem; margin-bottom: 6px; }
.ed-side label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.ed-side label input[type=range] { accent-color: var(--red); }
.ed-side label b { font-family: var(--mono); font-size: 0.85rem; }
.ed-status { padding: 8px 10px; border: 2px solid var(--ink); margin: 0; font-weight: 600; }
.ed-status.good { background: #d9e8c6; } .ed-status.bad { background: #f2cdbf; }
.ed-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ed-btns .tag { font-size: 0.85rem; padding: 8px 10px 8px 28px; }
.ed-btns .tag::before { left: 9px; width: 8px; height: 8px; margin-top: -4px; }
.ed-mine h3 { margin: 6px 0; }
.mine-row { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--line); padding: 3px 0; }
.mine-row .x { background: none; border: 0; color: var(--red); font-weight: 700; }
.hint { font-size: 0.85rem; color: var(--muted); margin: 0; }
.ed-side .back { align-self: flex-start; margin-top: auto; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 22px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 20; pointer-events: none; align-items: flex-end; }
.toast { background: var(--paper2); border: 2px solid var(--ink); padding: 8px 14px; box-shadow: 4px 4px 0 rgba(36, 38, 43, 0.4); max-width: 340px; animation: tin 0.25s ease-out; transition: opacity 0.5s, transform 0.5s; }
.toast.stamp { border: 3px double var(--red); }
.toast.stamp b { color: var(--red); font-family: var(--slab); font-weight: 400; margin-right: 6px; }
.toast.out { opacity: 0; transform: translateX(30px); }
@keyframes tin { from { transform: translateX(40px); opacity: 0; } }

@media (max-width: 900px) {
  .daily, .garage { grid-template-columns: 1fr; }
  .sheet { margin: 10px; padding: 18px 16px; }
  .title-wrap { padding: 24px 16px; }
  .tags .tag { min-width: 0; width: 100%; }
  .logo h1 { font-size: 3rem; }
  .screen-title { background: rgba(239, 228, 200, 0.94); }
  #workshop { grid-template-columns: 1fr; grid-template-rows: 55vh auto; }
  .postmark { width: 80px; height: 80px; font-size: 2.4rem; }
  #h-board { display: none; }
  #h-map { width: 120px; height: 120px; }
}
