/* R163/R494 — the terrain generator page, in the front door's glass: its photograph behind, the
   header, the panel and the footer as frosted panels, and the map in a dark window where land and
   water both read. The ids and the layout are R163–R190's. */
:root { --ink: #22302a; --muted: rgba(34, 48, 42, 0.66); --green: #4f9a49; --line: rgba(255, 255, 255, 0.58);
  --glass: rgba(255, 255, 255, 0.60); --glass-hi: rgba(255, 255, 255, 0.78); --field: rgba(255, 255, 255, 0.74); --field-line: rgba(34, 48, 42, 0.16); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
/* R172: header, the panel and the preview, footer — the ends pinned; R494: floating over the photograph */
body { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; height: 100vh; padding: 12px; font: 12.5px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: #1a211e; }
body::before { content: ''; position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(120% 100% at 50% 0%, rgba(44, 58, 52, 0.12) 0%, rgba(26, 33, 30, 0.40) 58%, rgba(18, 22, 20, 0.66) 100%),
    url('/img/day_bg.jpg') center / cover no-repeat, #1a211e; }
#tg-header, #tg-footer { position: sticky; z-index: 5; display: flex; align-items: center; gap: 14px; padding: 9px 14px; border-radius: 16px; }
#tg-header, #tg-footer, #tg-panel { background: var(--glass); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(18px) saturate(1.35); backdrop-filter: blur(18px) saturate(1.35);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24), inset 0 1px 0 var(--glass-hi); }
#tg-header { top: 0; flex-wrap: wrap; }
#tg-footer { bottom: 0; gap: 8px; display: grid; grid-template-columns: 1fr auto 1fr; }
/* R192: left the making, right the exports, and in the middle the way into the game */
.tg-foot-side { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tg-foot-right { justify-content: flex-end; }
#tg-head-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; flex: 1 1 auto; }
.tg-hfield { display: flex; align-items: center; gap: 7px; color: var(--muted); font-weight: 600; }
.tg-hfield select { max-width: 220px; }
.tg-hfield .tg-field input { width: 130px; }
.tg-spacer { flex: 1 1 auto; }

/* the brand links home, with the front door's mark */
.tg-brand { display: flex; align-items: center; gap: 10px; margin-right: 6px; color: inherit; text-decoration: none; }
.tg-brand .word b { display: block; font-size: 18px; font-weight: 800; color: #22302a; letter-spacing: -0.02em; line-height: 1.05; }
.tg-brand .word b span { color: #5aa552; }
/* R605: the logo is the brand now, the word under it the page's name */
.tg-brand .brand-logo { display: block; height: 40px; width: auto; margin: -5px 0; }
.tg-brand .word small { display: block; color: var(--muted); font-size: 11px; }
.tg-brand-col { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.tg-back { align-self: flex-start; padding: 4px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.55); border: 1px solid var(--field-line); color: var(--ink); text-decoration: none; font-size: 11px; font-weight: 700; }
.tg-back:hover { background: rgba(255, 255, 255, 0.85); }

/* R182: the panel is a drawer — its column slides to nothing and the lip on
   its edge (a tab, half out over the view) brings it back */
#tg-middle { --panel-w: 340px; position: relative; display: grid; grid-template-columns: var(--panel-w) 1fr; column-gap: 12px; min-height: 0; transition: grid-template-columns 0.22s ease; }
#tg-middle.tg-closed { grid-template-columns: 0px 1fr; }
#tg-middle.tg-closed { column-gap: 0; }
#tg-middle.tg-closed #tg-panel { visibility: hidden; padding-inline: 0; border: 0; }
#tg-drawer { position: absolute; z-index: 4; top: 50%; left: calc(var(--panel-w) + 12px); transform: translateY(-50%); width: 20px; height: 64px; padding: 0; border: 1px solid var(--line); border-left: 0; border-radius: 0 10px 10px 0;
  background: rgba(255, 255, 255, 0.72); color: var(--ink); font-size: 15px; line-height: 1; cursor: pointer; box-shadow: 2px 0 10px rgba(0, 0, 0, 0.22); transition: left 0.22s ease; }
#tg-drawer:hover, #tg-drawer:focus-visible { background: #fff; }
#tg-middle.tg-closed #tg-drawer { left: 0; }
@media (max-width: 760px) {
  body { height: auto; min-height: 100vh; padding: 8px; gap: 8px; }
  #tg-middle, #tg-middle.tg-closed { grid-template-columns: 1fr; row-gap: 8px; }
  #tg-middle.tg-closed #tg-panel { visibility: visible; padding-inline: 16px; }
  #tg-drawer { display: none; }   /* stacked, the panel is above the map: nothing to slide */
  #tg-view { height: 60vh; }
  #tg-footer { grid-template-columns: 1fr; }
  .tg-foot-right { justify-content: flex-start; }
}

#tg-panel { overflow-y: auto; padding: 6px 16px 18px; border-radius: 16px; }

details.tg-group { border-top: 1px solid rgba(34, 48, 42, 0.10); padding: 8px 0 4px; }
details.tg-group:first-child { border-top: 0; }
details.tg-group > summary { cursor: pointer; font-weight: 800; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); list-style: none; padding: 4px 0 6px; }
details.tg-group > summary::before { content: "▸ "; }
details.tg-group[open] > summary::before { content: "▾ "; }

.tg-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; padding: 3px 0; }
.tg-row > label { color: #34453c; }
.tg-row > b { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }
.tg-row > input[type=range], .tg-row > select, .tg-row > .tg-field { grid-column: 1 / -1; width: 100%; }
.tg-row.changed > label { color: #2f6a2a; font-weight: 700; }
.tg-row.changed > label::after { content: " •"; color: var(--green); }
.tg-row .hint { grid-column: 1 / -1; color: var(--muted); font-size: 10.5px; margin-top: -1px; }
.tg-row.check { grid-template-columns: auto 1fr; }
.tg-field { display: flex; gap: 6px; }
.tg-field input { flex: 1 1 auto; min-width: 0; }
input[type=text], select { font: inherit; font-size: 12px; border: 1px solid var(--field-line); border-radius: 9px; padding: 6px 8px; background: var(--field); color: var(--ink); }
input[type=text]:focus, select:focus { outline: 2px solid #7cc36a; outline-offset: -1px; }
input[type=range] { accent-color: var(--green); }

/* the buttons: glass pills, and one green call to action, Start World (R495) */
.tg-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
button { border: 1px solid var(--field-line); border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 12px; font-weight: 700; background: rgba(255, 255, 255, 0.55); color: var(--ink); cursor: pointer; transition: background 120ms ease, transform 120ms ease; }
button:hover { background: rgba(255, 255, 255, 0.88); }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, .tg-back:focus-visible, .tg-brand:focus-visible { outline: 2px solid #7cc36a; outline-offset: 2px; }
/* R495: Generate is the page's second action now, a white pill in green ink beside the green Start */
#tg-footer #tg-generate { padding: 9px 24px; color: #2e7a3b; background: rgba(255, 255, 255, 0.82); border: 1px solid rgba(79, 154, 73, 0.55); }
#tg-footer #tg-generate:hover:not(:disabled) { transform: translateY(-1px); }
/* R495: Start World, the page's one call to action: the front door's green pill and its turning glow */
#tg-footer #tg-start { position: relative; border: 0; padding: 13px 44px; font-size: 17px; font-weight: 800; letter-spacing: -0.01em; color: #fff;
  background: linear-gradient(135deg, #6cc061 0%, #3f8f43 62%, #2e7a3b 100%); box-shadow: 0 12px 34px rgba(63, 143, 67, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.35); }
@property --tg-a { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
.tg-cta { position: relative; display: inline-block; border-radius: 999px; isolation: isolate; }
.tg-cta::before, .tg-cta::after { content: ''; position: absolute; border-radius: inherit; pointer-events: none;
  background: conic-gradient(from var(--tg-a), rgba(108, 192, 97, 0) 0%, #b9f2a6 16%, #ffffff 28%, #6cc061 42%, rgba(108, 192, 97, 0) 58%, #dbffd0 78%, rgba(108, 192, 97, 0) 100%);
  animation: tg-turn 7s linear infinite; transition: opacity 200ms ease; }
.tg-cta::before { inset: -12px; z-index: -2; filter: blur(18px); opacity: 0.8; }
.tg-cta::after { inset: -2px; z-index: -1; padding: 2px;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); mask-composite: exclude; }
.tg-cta:has(#tg-start:disabled)::before, .tg-cta:has(#tg-start:disabled)::after { opacity: 0.15; }
@keyframes tg-turn { to { --tg-a: 360deg; } }
#tg-footer #tg-start:hover:not(:disabled) { transform: translateY(-1px); }
#tg-footer #tg-start:disabled { opacity: 0.5; cursor: default; }
#tg-stats { margin: 12px 0 0; padding: 9px 10px; background: rgba(255, 255, 255, 0.55); border: 1px solid var(--field-line); border-radius: 10px; font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: #34453c; white-space: pre-wrap; }

/* R494: the map in a dark window of its own, rounded like the panels beside it */
#tg-view { position: relative; display: grid; place-items: center; overflow: hidden; border-radius: 16px; border: 1px solid rgba(255, 255, 255, 0.30);
  background: radial-gradient(120% 90% at 50% 42%, #16202b 0%, #0b1016 70%, #070a0e 100%); box-shadow: 0 14px 40px rgba(0, 0, 0, 0.30); }
/* R183: whatever is showing shares the view's one cell — a stray sibling overlaps, it never stacks */
#tg-view > #tg-mapwrap, #tg-view > canvas { grid-area: 1 / 1; }
/* R173: the map and its spot layer share one box, so the stripes land exactly on the land */
#tg-mapwrap { position: relative; width: min(94%, calc(100vh - 180px)); aspect-ratio: 1 / 1; border-radius: 8px; box-shadow: 0 12px 40px rgba(0,0,0,0.5); overflow: hidden; }
#tg-mapwrap[hidden] { display: none; }
#tg-map, #tg-over { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: auto; }
#tg-over { pointer-events: none; }
@media (max-width: 760px) { #tg-mapwrap { width: min(94%, calc(60vh - 20px)); } }
#tg-progress { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); width: min(420px, 80%); display: flex; flex-direction: column; align-items: center; gap: 7px; }
#tg-progress[hidden] { display: none; }
#tg-stage { color: #cfe2f2; font-size: 12.5px; letter-spacing: .03em; text-shadow: 0 1px 10px rgba(0,0,0,0.6); }
#tg-bar { width: 100%; height: 3px; border-radius: 3px; background: rgba(190,220,245,0.16); overflow: hidden; }
#tg-bar i { display: block; height: 100%; width: 0; background: #9fd0ff; transition: width 200ms ease; }

/* R165 — the 3D view and the toggle. The toggle is a segmented pill in the
   map's top-right corner: glass on the dark ground, the chosen view in white
   so it reads as "on". */
#tg-view canvas[hidden] { display: none; }
#tg-iso { width: 96%; height: calc(100% - 30px); }
#tg-iso.stale { opacity: 0.45; transition: opacity 200ms ease; }
#tg-viewtoggle { position: absolute; top: 14px; right: 14px; z-index: 2; display: inline-flex; gap: 2px; padding: 3px;
  border-radius: 999px; background: rgba(252, 250, 246, 0.14); border: 1px solid rgba(255, 255, 255, 0.22); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
#tg-viewtoggle button { border: 0; background: transparent; color: #cfe2f2; border-radius: 999px; padding: 5px 13px; font-weight: 700; }
#tg-viewtoggle button:hover { background: rgba(255, 255, 255, 0.14); }
#tg-viewtoggle button[aria-pressed="true"], #tg-viewtoggle button[aria-pressed="true"]:hover { background: #fff; color: #22302a; }
/* R169: the 3D view turns under a sideways drag */
#tg-iso { cursor: grab; touch-action: none; }
#tg-iso:active { cursor: grabbing; }
/* R170: the three.js view */
#tg-gl { width: 96%; height: calc(100% - 30px); cursor: grab; touch-action: none; }
#tg-gl:active { cursor: grabbing; }
/* R183: three.js writes display:block on its canvas, and that beat a plain
   [hidden] — so after a visit to 3D the hidden canvas still took a row of the
   view's grid, and the 2D map sat half the height too high */
#tg-gl[hidden] { display: none !important; }
#tg-gl.stale { opacity: 0.45; transition: opacity 200ms ease; }
/* R176: the opened .glb's bar, top left of the view */
#tg-glbbar { position: absolute; top: 14px; left: 14px; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 5px 6px 5px 12px;
  border-radius: 999px; background: rgba(255, 255, 255, 0.88); color: var(--ink); font-size: 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3); }
#tg-glbbar[hidden] { display: none; }
#tg-glbbar button { padding: 3px 9px; border-radius: 999px; }
/* R495: the round info button, top right of the header, and the card it opens over the preview */
.tg-info-btn { flex: 0 0 auto; width: 42px; height: 42px; padding: 0; display: grid; place-items: center; border-radius: 50%;
  background: #fff; color: #2f68b8; border: 1px solid rgba(47, 104, 184, 0.35); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18); }
.tg-info-btn:hover { background: #eef5ff; transform: translateY(-1px); }
.tg-info-btn[aria-expanded="true"] { background: #3d7fd6; color: #fff; border-color: transparent; }
#tg-info { position: absolute; top: 14px; left: 14px; z-index: 3; width: min(360px, calc(100% - 28px)); max-height: calc(100% - 28px); overflow: auto;
  padding: 10px 12px 12px 14px; border-radius: 14px; color: var(--ink); background: rgba(255, 255, 255, 0.88); border: 1px solid rgba(255, 255, 255, 0.7);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); box-shadow: 0 18px 44px rgba(0, 0, 0, 0.42); }
#tg-info[hidden] { display: none; }
#tg-glbbar:not([hidden]) ~ #tg-info { top: 58px; }
.tg-info-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tg-info-head b { font-size: 13px; font-weight: 800; letter-spacing: -0.01em; }
#tg-info-close { width: 28px; height: 28px; padding: 0; display: grid; place-items: center; font-size: 13px; line-height: 1; }
#tg-info #tg-stats { margin: 8px 0 0; }
@media (prefers-reduced-motion: reduce) {
  button, #tg-middle, #tg-drawer { transition: none; }
  .tg-cta::before, .tg-cta::after { animation: none; }
}
