/* The single <dialog> element, reused for the sector picker, the evolution
   tree and settings. DISCOVER has a sidebar of its own (discover.css). */

dialog {
  width: min(1000px, 94vw);
  max-height: 90svh;
  padding: 27px 33px;
  border: 1px solid #6588a355;
  border-radius: 12px;
  background: linear-gradient(135deg, #111e30, #080f1d);
  box-shadow: 0 35px 130px #0009;
  color: #e0ebf8;
}
dialog::backdrop { background: #030811bf; backdrop-filter: blur(12px); }
/* Settings open over the live arena too; phones skip the per-frame blur for a deeper tint. */
@media (pointer: coarse) { dialog::backdrop { background: #030811e0; backdrop-filter: none; } }
dialog h2 { margin: 14px 0 20px; font-size: 33px; font-weight: 500; }

.dialog-header { display: flex; justify-content: space-between; align-items: center; }
/* BACK: only the app's full-screen pages show it (below). */
.dialog-back { display: none; align-items: center; gap: 6px; padding: 8px 10px 8px 0; background: transparent; font-family: var(--font-display); font-size: var(--label-md); font-weight: 500; letter-spacing: var(--track-md); color: #a0d4f2; }
.dialog-back svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dialog-back:hover { color: #e3f5ff; }

/* --- Evolution tree ---------------------------------------------------- */

dialog.dialog-wide { width: min(1200px, 96vw); }
.evo {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 26px;
  align-items: start;
}
.evo-map { overflow-x: auto; padding-bottom: 6px; }
.evo-tiers, .evo-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); column-gap: 46px; min-width: 740px; }

.evo-tier { padding-bottom: 9px; border-bottom: 1px solid var(--line); }
.evo-tier strong { display: block; font-family: var(--font-display); font-size: 12px; font-weight: 500; letter-spacing: 1.4px; color: var(--accent); }
.evo-tier span { font-family: var(--font-display); font-size: var(--label-sm); font-weight: 500; letter-spacing: 1px; color: #7690a8; text-transform: uppercase; }

.evo-grid { position: relative; grid-template-rows: repeat(6, minmax(62px, auto)); row-gap: 8px; padding-top: 16px; }
.evo-links { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.evo-links path { fill: none; stroke: #5f81a0; stroke-opacity: .28; stroke-width: 1.2; transition: stroke .2s, stroke-opacity .2s; }
.evo-links path.is-lit { stroke: var(--accent); stroke-opacity: .85; stroke-width: 1.6; }

.evo-node {
  position: relative;
  z-index: 1;
  align-self: center;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 3px;
  align-items: center;
  padding: 8px 12px 8px 7px;
  border: 1px solid #38536c80;
  border-radius: 7px;
  background: #0b1626f0;
  text-align: left;
  transition: border-color .2s, background .2s, opacity .2s, box-shadow .2s;
}
.evo-art { grid-row: 1 / 3; width: 46px; height: 46px; }
.evo-name { align-self: end; font-family: var(--font-display); font-size: 13px; font-weight: 500; color: #dcecf8; }
.evo-weapon { align-self: start; overflow: hidden; font-size: var(--label-sm); color: #7f97ae; text-overflow: ellipsis; white-space: nowrap; }
.evo-node:hover, .evo-node.is-lit { border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.evo-grid.is-tracing .evo-node:not(.is-lit) { opacity: .4; }
.evo-node[aria-pressed='true'] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 13%, #0b1626);
  box-shadow: 0 0 22px color-mix(in srgb, var(--accent) 22%, transparent);
}
.evo-node[aria-pressed='true'] .evo-name { color: #fff; }

/* Spec sheet for the selected ship. */
.evo-detail {
  position: sticky;
  top: 0;
  padding: 18px 18px 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 8%, #0b1626), #080f1c);
}
.evo-kicker { display: flex; gap: 12px; font-family: var(--font-display); font-size: var(--label-sm); font-weight: 500; letter-spacing: 1.6px; color: var(--accent); }
.evo-detail h3 { margin: 6px 0 2px; overflow: hidden; font-size: 26px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.evo-role { font-family: var(--font-display); font-size: 11px; font-weight: 500; color: #8ea6bd; }
.evo-preview { display: block; width: 100%; height: auto; margin: 6px 0 8px; filter: drop-shadow(0 12px 16px #0008); }
.evo-facts { display: grid; gap: 7px; margin: 0 0 14px; }
.evo-facts div { display: grid; grid-template-columns: 70px 1fr; gap: 8px; }
.evo-facts dt { font-family: var(--font-display); font-size: var(--label-sm); font-weight: 500; letter-spacing: 1px; color: #7690a8; text-transform: uppercase; }
.evo-facts dd { margin: 0; overflow: hidden; font-size: 12px; color: #d3e3f1; text-overflow: ellipsis; white-space: nowrap; }
.evo-stats { display: grid; gap: 9px; padding-top: 13px; border-top: 1px solid var(--line); }
.evo-stat { display: grid; grid-template-columns: 70px 1fr 52px 38px; align-items: center; gap: 8px; }
.evo-stat span { font-family: var(--font-display); font-size: var(--label-sm); font-weight: 500; letter-spacing: 1px; color: #7690a8; text-transform: uppercase; }
.evo-stat i { height: 4px; overflow: hidden; border-radius: 2px; background: #54708933; }
.evo-stat b { display: block; height: 100%; border-radius: 2px; background: var(--accent); }
.evo-stat strong { font-size: 11px; font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; color: #dcecf8; }
.evo-stat em { font-size: 10px; font-style: normal; text-align: right; font-variant-numeric: tabular-nums; }
.evo-stat em.up { color: #78ddb5; }
.evo-stat em.down { color: #e39a8a; }
.evo-trait { min-height: 1.4em; margin: 14px 0 0; overflow: hidden; font-size: 12px; color: #9fb4c8; text-overflow: ellipsis; white-space: nowrap; }
.evo-path { display: flex; overflow: hidden; white-space: nowrap; margin: 12px 0 0; padding: 0; list-style: none; font-family: var(--font-display); font-size: var(--label-sm); font-weight: 500; letter-spacing: .6px; color: #7690a8; }
.evo-path li:not(:last-child)::after { content: '\203A'; margin: 0 7px; color: #4f6a83; }
.evo-path li:last-child { color: var(--accent); }

@media (max-width: 980px) {
  .evo { grid-template-columns: 1fr; }
  .evo-detail { position: static; }
}

@media (max-width: 560px) {
  dialog { padding: 21px; }
  dialog h2 { font-size: 27px; }
}

/* --- Settings ---------------------------------------------------------- */

dialog.dialog-narrow { width: min(460px, 94vw); }
.settings { display: grid; }
.settings-group { display: grid; }
/* Each group's first row has no rule of its own; between the groups the second draws one. */
.settings-group + .settings-group { border-top: 1px solid var(--line); }
.setting {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  font-family: var(--font-display);
  font-weight: 500;
}
.setting:first-child { border-top: 0; }
.setting > span { font-size: var(--label-sm); letter-spacing: 1.5px; color: #a4b7ce; }
.setting > b { font-size: var(--label-md); font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; color: #dce9f5; }
.settings.is-muted .setting input, .settings.is-muted .setting > b { opacity: .4; }
/* On/off switch. */
.switch { grid-column: 3; justify-self: end; position: relative; width: 38px; height: 20px; padding: 0; border: 1px solid #7ea6c055; border-radius: 10px; background: #0a1522; }
.switch i { position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: #7d90a6; transition: transform .2s, background .2s; }
.switch[aria-checked='true'] { border-color: #80e3fa88; background: #14324a; }
.switch[aria-checked='true'] i { transform: translateX(18px); background: var(--cyan); box-shadow: 0 0 8px #80e3fa99; }
/* Volume sliders: the same thin track as the ship spec bars. */
.setting input[type='range'] {
  width: 100%;
  height: 3px;
  margin: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, #afcfe6 0 var(--fill), #7897b726 0);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.setting input[type='range']::-webkit-slider-thumb { width: 14px; height: 14px; border: 2px solid var(--blue); border-radius: 50%; background: #e7f6ff; box-shadow: 0 0 8px #6dcaff66; -webkit-appearance: none; }
.setting input[type='range']::-moz-range-thumb { width: 10px; height: 10px; border: 2px solid var(--blue); border-radius: 50%; background: #e7f6ff; box-shadow: 0 0 8px #6dcaff66; }
.setting input[type='range']::-moz-range-track { background: transparent; }
/* One-of-a-kind choices (graphics, controls): a row of buttons under the label. */
.setting-choice { grid-template-columns: minmax(0, 1fr); gap: 10px; }
.choices { display: flex; gap: 5px; }
.setting-note { float: right; font-size: var(--label-sm); font-variant-numeric: tabular-nums; letter-spacing: 1px; color: #6f879e; }
.choices button {
  flex: 1;
  min-width: 0;
  padding: 8px 2px;
  border: 1px solid #7ea6c033;
  border-radius: 4px;
  background: #0a1522;
  font: 500 var(--label-sm) var(--font-display);
  letter-spacing: 1.1px;
  color: #8fa6bd;
  cursor: pointer;
}
.choices button:hover { border-color: #7ad1f388; color: #d7ecfa; }
.choices button[aria-pressed='true'] { border-color: #80e3fa88; background: #14324a; color: #e3f5ff; box-shadow: 0 0 10px #80e3fa33; }
.settings .text-button { justify-self: start; margin-top: 8px; }

/* The destination page's SERVER row (app.js): AUTO or one server, each with its ping. */
.server-switch { display: flex; align-items: center; gap: 18px; margin: 0 0 14px; font-family: var(--font-display); font-weight: 500; }
.server-switch > span { font-size: var(--label-sm); letter-spacing: 1.5px; color: #a4b7ce; }
.server-switch .choices { flex: 1; max-width: 560px; }
.choices button small { display: block; margin-top: 3px; font-size: 9px; letter-spacing: .6px; color: #7f97ad; }
.choices button[aria-pressed='true'] small { color: #b9dcf0; }

/* --- Android app: every dialog is a full-screen page ------------------- */

/* Settings, destinations, the evolution tree and the origins all fill
   the screen, clear of the camera cutout, under one header row: BACK on the left,
   the close button on the right; no eyebrow or title. The page below it
   scrolls when it is taller than the screen. */
html.is-app dialog {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 10px calc(4.3vw + var(--cutout-right)) 16px calc(4.3vw + var(--cutout-left));
  border: 0;
  border-radius: 0;
  box-shadow: none;
  outline: none;
}
html.is-app dialog[open] { display: flex; flex-direction: column; }
html.is-app .dialog-header { flex: none; margin-bottom: 10px; }
/* A page opens with focus on BACK; a touch screen needs no focus ring for that. */
html.is-app .dialog-header button:focus-visible { outline: none; }
html.is-app .dialog-back { display: inline-flex; gap: 7px; font-size: 13px; }
html.is-app .dialog-back svg { width: 19px; height: 19px; }
html.is-app #dialog-close { width: 38px; height: 38px; font-size: 20px; }
html.is-app #dialog-eyebrow, html.is-app #dialog-title { display: none; }
html.is-app #dialog-content { flex: 1; width: 100%; min-height: 0; overflow-y: auto; }
/* Settings keep a reading width in the middle of the page. */
html.is-app dialog.dialog-narrow #dialog-content { max-width: 900px; margin: 0 auto; }

/* Settings: sound on the left, display on the right. */
html.is-app .settings { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 36px; align-items: start; }
html.is-app .settings-group + .settings-group { border-top: 0; }
html.is-app .setting { padding: 10px 0; }
html.is-app .setting-choice { gap: 7px; }
html.is-app .choices button { padding: 7px 2px; }
html.is-app .settings .text-button { grid-column: 1 / -1; margin-top: 4px; }

/* Evolution tree: smaller nodes and a smaller portrait in the spec sheet. */
html.is-app .evo { grid-template-columns: minmax(0, 1fr) 230px; gap: 18px; }
html.is-app .evo-tier { padding-bottom: 5px; }
html.is-app .evo-grid { grid-template-rows: repeat(6, minmax(44px, auto)); row-gap: 5px; padding-top: 8px; }
html.is-app .evo-node { grid-template-columns: 34px minmax(0, 1fr); padding: 5px 9px 5px 5px; }
html.is-app .evo-art { width: 34px; height: 34px; }
html.is-app .evo-detail { padding: 12px 14px; }
html.is-app .evo-detail h3 { font-size: 20px; }
html.is-app .evo-preview { width: auto; max-width: 100%; height: 92px; margin: 4px auto 6px; }
html.is-app .evo-facts { gap: 4px; margin-bottom: 8px; }
html.is-app .evo-stats { gap: 6px; padding-top: 8px; }
html.is-app .evo-trait { margin-top: 8px; }
html.is-app .evo-path { margin-top: 6px; }

/* Destinations: wider, shorter artwork, so both rows of four fit. */
html.is-app .sector-gallery { gap: 12px; padding-top: 6px; }
html.is-app .sector-art { aspect-ratio: 16 / 7.5; }
html.is-app .sector-copy { padding: 9px 11px 10px; }
html.is-app .sector-copy small { margin-top: 3px; }

/* --- Origins (Android app) --------------------------------------------- */

/* The origin picker is a page of five ships, centred under the header:
   picking one closes it (app.js). */
dialog.dialog-fleet #dialog-content { display: flex; align-items: center; }
dialog.dialog-fleet #dialog-content .fleet-grid { flex: 1; }
dialog.dialog-fleet .fleet-grid { overflow: visible; padding: 0; }
/* Each card stacks the ship over its name, role and price, so none is cut off. */
dialog.dialog-fleet .fleet-card { flex-direction: column; justify-content: center; align-items: center; gap: 12px; height: min(64dvh, 250px); padding: 12px 10px; }
dialog.dialog-fleet .fleet-card canvas { width: 100%; height: min(30dvh, 120px); }
dialog.dialog-fleet .fleet-card > div { padding: 0; text-align: center; }
dialog.dialog-fleet .fleet-card h3 { font-size: 14px; }
