.meridian {
  color: var(--studio-text, #faf4e7);
  color-scheme: dark;
  background: var(--studio-bg, #182b23);
  font: 1rem/1.55 var(--studio-body, system-ui);
  --surface: var(--studio-surface, #2c493a);
  --line: var(--studio-border, #779280);
  --gold: var(--studio-amber, #efc48a);
}

@scope (.meridian) {
  *, *::before, *::after { box-sizing: border-box; }
  [hidden] { display: none !important; }
  :focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
  h1, h2, .site-name { font-family: var(--studio-display, Georgia, serif); }
  h1, h2, p { margin: 0; }
  h1 { font-size: clamp(2.45rem, 5vw, 4.15rem); line-height: 1.08; }
  :is(.workspace-panel, .map-tools, #handoff) h2 { font-size: clamp(1.5rem, 2.4vw, 2rem); line-height: 1.18; }

  .studio-header, #editor, #game {
    max-width: var(--studio-width, 83rem);
    margin-inline: auto;
    padding: 1rem var(--studio-gutter, 1rem);
  }
  .studio-header, .toolbar, .matchbar, .map-tools, .zoom-tools {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
  }
  .studio-header, .map-tools { justify-content: space-between; }
  .studio-header { padding-block: clamp(1.65rem, 4vw, 3.2rem) 1rem; }
  .studio-header p, #count, #energy-summary { color: var(--studio-muted, #d2dfd3); }
  .toolbar { align-items: end; }
  .draft-note { margin-top: .65rem; color: var(--studio-muted, #d2dfd3); font-size: .9rem; }
  .test-tools { margin-top: 1rem; padding-bottom: 1rem; }
  #editorstatus, #status { min-height: 1.5em; margin-block: .5rem; color: #f6d6a1; }

  button, .upload, select, input, textarea {
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--studio-inset, #1b3026);
    color: inherit;
    font: inherit;
    padding: .45rem .6rem;
    min-width: 0;
  }
  button, select, input:not([type='checkbox'], [type='file']) { min-height: 44px; }
  button, .upload, summary { cursor: pointer; }
  button:not(.meridian-card):is(:hover:not(:disabled), [aria-pressed="true"]) { border-color: var(--gold); background: var(--studio-surface-hover, #355646); }
  button:disabled { opacity: .6; cursor: default; }
  :is(#end, #test, #exportcsv) { background: var(--gold); border-color: var(--gold); color: var(--studio-ink, #18241a); font-weight: 700; }
  :is(#end, #test, #exportcsv):hover:not(:disabled) { background: var(--studio-amber-hover, #ffdbab); }
  .upload { padding-block: .28rem; font-size: .86rem; }
  .upload input { display: block; max-width: 180px; margin-top: .1rem; padding: 0; border: 0; font-size: .78rem; }

  .editgrid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .8fr) minmax(0, 1.15fr); gap: 14px; }
  .workspace-panel { min-width: 0; padding: clamp(.85rem, 1.9vw, 1.45rem); border: 1px solid var(--line); border-radius: var(--studio-radius, 16px); background: var(--surface); }
  .workspace-panel h2 { margin-bottom: .55rem; }
  .workspace-panel label, .test-tools label { display: block; margin-block: .45rem; font-size: .88rem; }
  label :is(input,select,textarea):not([type="checkbox"]) { display: block; width: 100%; margin-top: .16rem; }
  textarea { resize: vertical; }
  label [type="checkbox"] { margin-inline-start: .55rem; }
  label [type="file"] { font-size: .79rem; }
  #cardform button, #exportcsv { margin-block: .35rem; }
  #preview a { display: inline-block; margin-top: .65rem; color: var(--gold); }

  .energy-breakdown { margin-block: .6rem; }
  .energy-breakdown summary { font-weight: 650; }
  #energy-summary { margin-top: .35rem; font-size: .85rem; }
  #energycurve { display: grid; grid-template-columns: 1fr auto; gap: .15rem .5rem; max-width: 12rem; margin: .35rem 0; }
  #energycurve dd { margin: 0; font-variant-numeric: tabular-nums; }
  #decklist { max-height: 20rem; overflow: auto; margin-block: .35rem; padding-inline: .2rem .45rem; }
  #decklist label { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
  #decklist select { width: auto; flex: 0 0 3.5rem; }

  .map-viewport {
    max-height: min(75svh, 780px);
    overflow: auto;
    margin-top: 8px;
    border: 1px solid var(--line);
    border-radius: var(--studio-radius, 16px);
    background: var(--studio-inset, #1b3026);
  }
  .map { position: relative; isolation: isolate; width: 100%; }
  :is(#board-art, .routes) { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
  #board-art { object-fit: fill; }
  .routes polyline {
    fill: none;
    stroke: #f0cb94;
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 1px 1px #11191c);
  }
  .routes .closed { stroke-dasharray: 3 4; opacity: .58; }
  .routes .open { stroke: #ffe493; stroke-width: 3; }
  .site {
    position: absolute;
    transform: translate(-50%, -50%);
    width: min(14%, 144px);
    border: 1px solid #b89865;
    border-radius: 5px;
    background: #111d20ed;
    padding: 3px;
    text-align: center;
    box-shadow: 0 4px 12px #0009;
  }
  .site-name { width: 100%; min-height: 0; padding: .2rem .1rem; font-size: clamp(.75rem, 1.1vw, 1rem); line-height: 1.15; }
  .site small { display: block; margin-block: 2px; color: var(--gold); font-size: .7rem; }
  .pieces { display: flex; justify-content: center; flex-wrap: wrap; gap: 3px; }
  .piece { min-height: 0; border-color: #89cde1; padding: 2px 4px; font-size: .7rem; }
  .piece.enemy { border-color: #edaa78; }
  .zoom-tools output { min-width: 3rem; text-align: center; }

  #hand { display: flex; align-items: flex-start; gap: .72rem; overflow-x: auto; padding: .5rem .3rem .95rem; }
  #hand > .meridian-card { flex: 0 0 clamp(174px, 26vw, 194px); }
  .preview-panel .meridian-card { max-width: 21rem; margin-inline: auto; }
  dialog { border: 1px solid var(--line); border-radius: var(--studio-radius, 16px); padding: 24px; background: var(--surface); color: var(--studio-text, #faf4e7); }
  dialog::backdrop { background: #12231ceb; }
  dialog p { margin-block: .65rem; }

  @media (max-width: 780px) {
    .editgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .workspace-panel:last-child { grid-column: 1 / -1; }
    .site-name, .site small, .piece { font-size: .65rem; }
    .site { padding: 1px; width: min(16%, 100px); }
  }
  @media (max-width: 500px) {
    .editgrid { grid-template-columns: minmax(0, 1fr); }
  }
}
