/* Project D · Island Viewer — ink & parchment chrome taken from the game's launcher art (Barlow, brush strokes),
   domain colours taken from the client (PresetColor.EstateArea / ClanTerritory / PlayerEstateArea). */

@font-face { font-family: "Barlow"; src: url("../assets/fonts/Barlow-Regular.ttf?v=861dd982c626") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Barlow"; src: url("../assets/fonts/Barlow-SemiBold.ttf?v=861dd982c626") format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url("../assets/fonts/BarlowCondensed-ExtraBold.ttf?v=861dd982c626") format("truetype"); font-weight: 800; font-display: swap; }

:root {
  --ink-0: #0e0c08;
  --ink-1: #16130e;
  --ink-2: #1f1b14;
  --ink-3: #2a251c;
  --line: #3a3326;
  --line-2: #574c38;
  --paper: #efe6d2;
  --paper-2: #cbbfa5;
  --paper-3: #978c75;
  --amber: #ffa700;        /* PresetColor.EstateArea — a domain on the in-game map */
  --clan: #4de900;         /* PresetColor.PlayerClanTerritory */
  --select: #00b0ff;       /* PresetColor.PlayerEstateArea — used for the selected domain */
  --civil: #ffd25a;
  --ok: #8fd16a;
  --radius: 10px;
  --radius-s: 7px;
  --topbar: 60px;
  --side: 284px;
  --panel: 348px;
  --shadow: 0 10px 30px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.35);
  --font: "Barlow", "Segoe UI", system-ui, sans-serif;
  --font-head: "Barlow Condensed", "Barlow", "Arial Narrow", sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--ink-0);
  color: var(--paper);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 99; background: var(--amber); color: #000; padding: 8px 12px; border-radius: 6px; }
.skip:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ── layout ─────────────────────────────────────────────── */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr) var(--panel);
  grid-template-rows: var(--topbar) minmax(0, 1fr);
  grid-template-areas: "top top top" "side stage panel";
}
.topbar { grid-area: top; }
.drawer { grid-area: side; }
.stage { grid-area: stage; }
.panel { grid-area: panel; }

/* ── top bar ────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px 0 14px;
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(180deg, #1a1610, #120f0b);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; width: calc(var(--side) - 30px); }
.brand-logo { height: 30px; width: auto; filter: invert(.92) sepia(.35) saturate(.6); }
.brand-sub {
  font: 800 13px/1 var(--font-head); letter-spacing: .14em; text-transform: uppercase; color: var(--paper-3);
  white-space: nowrap; border-left: 1px solid var(--line-2); padding-left: 10px;
}
.island-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1; }
.island-title h1 {
  margin: 0; font: 800 26px/1 var(--font-head); letter-spacing: .02em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.island-kind {
  font: 800 12px/1 var(--font-head); letter-spacing: .12em; text-transform: uppercase;
  padding: 5px 8px 4px; border-radius: 4px; color: #1a1408; background: var(--amber); flex: none; transform: translateY(-3px);
}
.island-kind.civilized { background: var(--civil); }
.live {
  display: flex; align-items: center; gap: 8px; flex: none;
  padding: 6px 12px; border: 1px solid var(--line-2); border-radius: 999px; background: rgba(0,0,0,.25);
  font-size: 13px; color: var(--paper-2);
}
.live b { color: var(--ok); letter-spacing: .08em; font-weight: 600; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); animation: pulse 2.4s infinite; }
.live.stale b { color: var(--amber); } .live.stale .live-dot { background: var(--amber); animation: none; }
.live-next { color: var(--paper-3); border-left: 1px solid var(--line-2); padding-left: 8px; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(143,209,106,.55); } 70% { box-shadow: 0 0 0 9px rgba(143,209,106,0); } 100% { box-shadow: 0 0 0 0 rgba(143,209,106,0); } }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border-radius: var(--radius-s); border: 1px solid var(--line-2); background: var(--ink-2); color: var(--paper);
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: var(--ink-3); border-color: #6d604a; }
.icon-btn:active { transform: translateY(1px); }
.only-compact { display: none; }

/* ── island list ────────────────────────────────────────── */
.drawer {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--ink-1); border-right: 1px solid var(--line);
  z-index: 20;
}
.drawer-head { padding: 12px 12px 8px; }
.seg { display: flex; background: var(--ink-0); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button {
  flex: 1; border: 0; background: none; padding: 7px 8px; border-radius: 6px;
  font: 800 13px/1 var(--font-head); letter-spacing: .1em; text-transform: uppercase; color: var(--paper-3);
}
.seg button[aria-selected="true"] { background: var(--ink-3); color: var(--paper); box-shadow: inset 0 0 0 1px var(--line-2); }
.island-list { list-style: none; margin: 0; padding: 4px 10px 12px; overflow-y: auto; flex: 1; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.group-h {
  margin: 14px 4px 8px; display: flex; align-items: center; gap: 8px;
  font: 800 13px/1 var(--font-head); letter-spacing: .16em; text-transform: uppercase; color: var(--paper-3);
}
.group-h::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.island-card {
  width: 100%; display: grid; grid-template-columns: 58px 1fr; gap: 11px; align-items: center; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius); padding: 7px; margin-bottom: 4px;
  transition: background .15s, border-color .15s;
}
.island-card:hover { background: var(--ink-2); border-color: var(--line); }
.island-card[aria-current="true"] { background: linear-gradient(90deg, rgba(255,167,0,.14), rgba(255,167,0,.03)); border-color: rgba(255,167,0,.45); }
.island-card canvas { width: 58px; height: 58px; display: block; border-radius: 8px; background: #264074; box-shadow: inset 0 0 0 1px rgba(0,0,0,.4); }
.island-card .nm { display: block; font: 800 18px/1.05 var(--font-head); text-transform: uppercase; letter-spacing: .03em; }
.island-card .sub { display: block; margin-top: 3px; font-size: 12.5px; color: var(--paper-3); }
.island-card .meta { display: flex; gap: 10px; margin-top: 5px; font-size: 12px; color: var(--paper-2); }
.island-card .meta span { display: inline-flex; align-items: center; gap: 4px; }
.island-card .meta i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.drawer-foot { padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); font-size: 12px; color: var(--paper-3); }
.scrim { display: none; }

/* ── stage ──────────────────────────────────────────────── */
.stage { position: relative; overflow: hidden; background: radial-gradient(120% 90% at 50% 40%, #2b5d74 0%, #173a52 60%, #0f2738 100%); touch-action: none; }
.view3d, .view2d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.view2d[hidden], .view3d[hidden] { display: none; }
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.tag {
  position: absolute; left: 0; top: 0; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px 3px 6px; border-radius: 6px;
  background: rgba(14,12,8,.8); border: 1px solid rgba(255,255,255,.14); color: #fff;
  font: 600 12.5px/1.2 var(--font); text-shadow: 0 1px 2px #000; pointer-events: auto; cursor: pointer;
}
.tag i { width: 9px; height: 9px; border-radius: 2px; background: var(--amber); flex: none; }
.tag.clan i { background: var(--clan); }
.tag.civilized i { background: var(--civil); }
.tag.sel { border-color: var(--select); background: rgba(0,60,90,.9); }

.viewswitch { position: absolute; top: 14px; left: 14px; z-index: 5; box-shadow: var(--shadow); background: rgba(14,12,8,.86); }
.viewswitch button { min-width: 64px; padding: 9px 12px; }

.zoombar {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%); z-index: 5;
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px;
  background: rgba(14,12,8,.86); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.zoombar .icon-btn { width: 42px; height: 42px; }
.zoom-level { font: 600 11.5px/1 var(--mono); color: var(--paper-2); padding: 3px 0; }
.zsep { width: 26px; height: 1px; background: var(--line); margin: 2px 0; }
.app[data-view="map"] [data-only="3d"] { display: none; }

.layers { position: absolute; left: 14px; bottom: 14px; z-index: 5; display: flex; gap: 6px; flex-wrap: wrap; }
.layers label {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 11px; border-radius: 9px; cursor: pointer;
  background: rgba(14,12,8,.86); border: 1px solid var(--line); font-size: 13px; color: var(--paper-2); box-shadow: var(--shadow);
  user-select: none;
}
.layers input { accent-color: var(--amber); width: 16px; height: 16px; margin: 0; }
.coords {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 4;
  padding: 6px 12px; border-radius: 8px; background: rgba(14,12,8,.78); border: 1px solid var(--line);
  font: 600 13px/1 var(--mono); color: #fff;
}
.coords b { color: #f3c85b; font-weight: 600; }
.legend {
  position: absolute; right: 70px; bottom: 14px; z-index: 5; max-width: 240px;
  background: rgba(14,12,8,.9); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); font-size: 13px;
}
.legend summary { cursor: pointer; padding: 9px 12px; font: 800 13px/1 var(--font-head); letter-spacing: .12em; text-transform: uppercase; color: var(--paper-2); list-style: none; }
.legend summary::-webkit-details-marker { display: none; }
.legend ul { list-style: none; margin: 0; padding: 0 12px 10px; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 8px; color: var(--paper-2); }
.sw { width: 14px; height: 14px; border-radius: 3px; flex: none; display: inline-block; }
.sw-tamed { background: rgba(255,167,0,.35); box-shadow: inset 0 0 0 2px var(--amber); }
.sw-civil { background: rgba(255,210,90,.35); box-shadow: inset 0 0 0 2px var(--civil); }
.sw-clan { background: rgba(77,233,0,.3); box-shadow: inset 0 0 0 2px var(--clan); }
.sw-house { background: linear-gradient(135deg, #8a6d4c 50%, #5d564d 50%); }
.sw-field { background: repeating-linear-gradient(90deg, #4b3f28 0 3px, #6b5a35 3px 5px); }
.sw-road { background: #6f6556; }

.loading {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; z-index: 8;
  background: rgba(10,9,6,.55); font: 800 16px/1 var(--font-head); letter-spacing: .14em; text-transform: uppercase; color: var(--paper-2);
  transition: opacity .25s;
}
.loading.done { opacity: 0; pointer-events: none; }
.loading-ink { width: 54px; height: 54px; border-radius: 50%; border: 4px solid rgba(255,255,255,.12); border-top-color: var(--amber); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* small pill while buildings / nature stream in after the first paint */
.streaming {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 6; display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 999px; background: rgba(14,12,8,.86); box-shadow: var(--shadow);
  font: 800 12px/1 var(--font-head); letter-spacing: .12em; text-transform: uppercase; color: var(--paper-2);
}
.streaming[hidden] { display: none; }
.streaming .loading-ink { width: 14px; height: 14px; border-width: 2px; }

/* ── info panel ─────────────────────────────────────────── */
.panel {
  display: flex; flex-direction: column; min-height: 0; position: relative;
  background: var(--ink-1); border-left: 1px solid var(--line); z-index: 20;
}
.panel-grip { display: none; }
.stats { padding: 14px 14px 6px; display: grid; grid-template-columns: repeat(3, 1fr); }
.stat { padding: 10px 10px 9px; border: 1px solid var(--line); margin: 0 -1px -1px 0; background: var(--ink-2); }
.stats .stat:first-child { border-top-left-radius: var(--radius); }
.stats .stat:nth-child(3) { border-top-right-radius: var(--radius); }
.stats .stat:nth-child(4) { border-bottom-left-radius: var(--radius); }
.stats .stat:last-child { border-bottom-right-radius: var(--radius); }
.stat b { display: block; font: 800 24px/1 var(--font-head); letter-spacing: .02em; }
.stat span { display: block; margin-top: 4px; font-size: 11.5px; color: var(--paper-3); text-transform: uppercase; letter-spacing: .06em; }
.panel-body { display: flex; flex-direction: column; min-height: 0; flex: 1; padding: 6px 14px 0; }
.search { position: relative; margin: 6px 0 10px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--paper-3); }
.search input {
  width: 100%; padding: 10px 12px 10px 36px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--ink-0);
  font-size: 14px; outline: none;
}
.search input:focus { border-color: var(--amber); }
.panel-h {
  margin: 4px 2px 8px; font: 800 15px/1 var(--font-head); letter-spacing: .14em; text-transform: uppercase; color: var(--paper-2);
  display: flex; align-items: center; gap: 8px;
}
.panel-h span { color: var(--paper-3); }
.domain-list { list-style: none; margin: 0 -6px; padding: 0 6px 16px; overflow-y: auto; flex: 1; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.domain {
  width: 100%; display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; text-align: left;
  padding: 8px; border-radius: 9px; border: 1px solid transparent; background: none; margin-bottom: 2px;
}
.domain:hover { background: var(--ink-2); border-color: var(--line); }
.domain[aria-current="true"] { background: rgba(0,176,255,.1); border-color: rgba(0,176,255,.5); }
.avatar {
  width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center;
  font: 800 16px/1 var(--font-head); color: #1a1408; background: var(--amber);
}
.avatar.clan { background: var(--clan); }
.avatar.civilized { background: var(--civil); }
.domain .who { min-width: 0; }
.domain .who b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.domain .who small { display: block; font-size: 12px; color: var(--paper-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.domain .cells { font: 600 12px/1 var(--mono); color: var(--paper-2); background: var(--ink-0); border: 1px solid var(--line); padding: 4px 6px; border-radius: 6px; }

.detail { position: absolute; inset: 0; background: var(--ink-1); display: flex; flex-direction: column; z-index: 3; animation: slidein .18s ease-out; }
.detail[hidden] { display: none; }
@keyframes slidein { from { transform: translateX(14px); opacity: 0; } }
.detail-head { display: flex; align-items: center; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); }
.detail-head h3 { margin: 0; font: 800 22px/1.05 var(--font-head); text-transform: uppercase; letter-spacing: .02em; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.detail-head .sub { font-size: 12.5px; color: var(--paper-3); }
.detail-body { padding: 12px 14px 20px; overflow-y: auto; flex: 1; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; margin: 0 0 14px; font-size: 14px; }
.kv dt { color: var(--paper-3); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 8px; background: var(--ink-2); border: 1px solid var(--line); font-size: 12.5px; color: var(--paper-2); }
.chip b { color: var(--paper); font-weight: 600; }
.sub-h { margin: 16px 0 8px; font: 800 13px/1 var(--font-head); letter-spacing: .14em; text-transform: uppercase; color: var(--paper-3); }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 60; background: var(--ink-2); border: 1px solid var(--line-2); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; }

/* ── ≤1180px: island list becomes a drawer ─────────────── */
@media (max-width: 1180px) {
  :root { --panel: 320px; }
  .app { grid-template-columns: minmax(0, 1fr) var(--panel); grid-template-areas: "top top" "stage panel"; }
  .only-compact { display: inline-grid; }
  .brand { width: auto; }
  .drawer {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(340px, 86vw);
    padding-top: env(safe-area-inset-top);
    transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow); z-index: 50;
  }
  .app.drawer-open .drawer { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 45; }
  .scrim[hidden] { display: none; }
}

/* ── ≤820px: phones — full-screen map + bottom sheet ───── */
@media (max-width: 820px) {
  :root { --topbar: 56px; --peek: 150px; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "stage"; }
  .topbar { gap: 10px; padding: 0 10px; padding-top: env(safe-area-inset-top); }
  .brand { display: none; }
  .island-title { flex-direction: column; align-items: flex-start; gap: 3px; }
  .island-title h1 { font-size: 21px; max-width: 100%; }
  .island-kind { transform: none; font-size: 10.5px; padding: 3px 6px 2px; }
  .live { padding: 5px 9px; font-size: 12px; }
  .live-next { display: none; }
  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; height: 72dvh; z-index: 25;
    border-left: 0; border-top: 1px solid var(--line-2); border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 30px rgba(0,0,0,.45);
    transform: translateY(calc(100% - var(--peek)));
    transition: transform .25s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .app.sheet-open .panel { transform: none; }
  .panel-grip { display: block; height: 22px; flex: none; cursor: grab; touch-action: none; position: relative; }
  .panel-grip::before { content: ""; position: absolute; left: 50%; top: 8px; width: 44px; height: 5px; border-radius: 3px; background: var(--line-2); transform: translateX(-50%); }
  .stats { padding: 0 12px 8px; }
  .stat { padding: 8px 8px 7px; }
  .stat b { font-size: 20px; }
  .stat span { font-size: 10.5px; }
  .detail { border-radius: 16px 16px 0 0; }
  .viewswitch { top: 10px; left: 10px; }
  .viewswitch button { min-width: 54px; padding: 8px 10px; }
  .zoombar { right: 10px; top: 10px; transform: none; padding: 5px; gap: 4px; }
  .zoombar .icon-btn { width: 40px; height: 40px; }
  .zoom-level { display: none; }
  .layers { left: 10px; bottom: calc(var(--peek) + 10px); flex-direction: column; align-items: flex-start; }
  .layers label { padding: 7px 10px; font-size: 12.5px; }
  .coords, .legend { display: none; }
}

/* ── hidden UI: only the map, full window (H / Esc, or ?ui=0) ── */
.app.ui-hidden { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "stage"; }
.app.ui-hidden :is(.topbar, .drawer, .scrim, .panel, .viewswitch, .zoombar, .layers, .coords, .legend, .labels, .streaming) {
  display: none !important;
}
.ui-show {
  position: absolute; z-index: 7;
  top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  background: rgba(14,12,8,.72); box-shadow: var(--shadow); transition: opacity .4s;
}
.ui-show[hidden] { display: none; }
.ui-show.idle { opacity: 0; pointer-events: none; }
.ui-show:focus-visible { opacity: 1; pointer-events: auto; }

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