:root {
  font-family: system-ui, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color-scheme: light;
  color: var(--ink);
  background: var(--surface);
  --surface: #fff;
  --accent: #176947;
  --ink: #172621;
  --muted: #596961;
  --field: #f1f5f3;
  --line: #dce6df;
  --on-accent: #fff;
  --disabled-ink: #617169;
  --disabled-surface: #e9eeeb;
  --selected: #eaf5ef;
  --selected-line: #73a68b;
  --option-line: #b9c7bf;
  --region-land: #d2e4d9;
  --region-land-muted: #e5ebe8;
  --region-edge: #8ca99a;
  --hud: #fffffff2;
  --hud-line: #fff9;
  --map-credit: #223b2e;
  --map-credit-shadow: #fff;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #171717;
  --accent: #7bd3a7;
  --ink: #f2f2f2;
  --muted: #b2b2b2;
  --field: #222222;
  --line: #3b3b3b;
  --on-accent: #15241b;
  --disabled-ink: #adadad;
  --disabled-surface: #303030;
  --selected: #292929;
  --selected-line: #72b994;
  --option-line: #727272;
  --region-land: #444444;
  --region-land-muted: #303030;
  --region-edge: #828282;
  --hud: #1c1c1ced;
  --hud-line: #525252e0;
  --map-credit: #f6f6f6;
  --map-credit-shadow: #161616;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1, h2, p { margin: 0; }
button, input { font: inherit; }
button {
  min-height: 42px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}
button:disabled { cursor: default; }
input { width: 100%; min-width: 0; color: var(--ink); }
input::placeholder { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { border-color: transparent; color: var(--on-accent); background: var(--accent); }
.primary:disabled { color: var(--disabled-ink); background: var(--disabled-surface); }

#entry {
  display: flex;
  justify-content: center;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.entry-page {
  display: flex;
  flex-direction: column;
  width: min(100%, 408px);
  min-height: 510px;
  margin-block: clamp(24px, 7vh, 64px);
  padding: 12px 15px 18px;
}
.entry-top, .entry-back-row { display: flex; align-items: center; min-height: 44px; margin-bottom: 40px; gap: 10px; }
.entry-top { justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.55rem; font-weight: 780; letter-spacing: -.075em; }
.brand-accent { color: var(--accent); }
.power-mark { display: grid; place-items: center; position: relative; width: 35px; height: 35px; border-radius: 11px; background: var(--accent); }
.power-mark::before { content: ""; width: 13px; height: 13px; margin-top: 3px; border: 2px solid var(--on-accent); border-top-color: transparent; border-radius: 50%; }
.power-mark::after { content: ""; position: absolute; top: 8px; width: 2px; height: 8px; background: var(--on-accent); border-radius: 2px; }
.entry-fields { display: grid; gap: 12px; }
.entry-fields h2, .entry-title { margin: 0 0 6px; font-size: 1.68rem; font-weight: 760; line-height: 1.2; letter-spacing: -.06em; }
.search-field, #nickname {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 50px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--field);
}
.search-field:focus-within, #nickname:focus { background: var(--surface); border-color: var(--accent); }
.search-field input { min-height: 46px; padding: 0; background: transparent; border: 0; outline-offset: -2px; }
.search-icon { position: relative; flex: none; width: 13px; height: 13px; border: 1.75px solid var(--muted); border-radius: 50%; margin: 0 3px 2px 0; }
.search-icon::after { content: ""; position: absolute; right: -4px; bottom: -2px; width: 5px; height: 1.75px; transform: rotate(45deg); background: var(--muted); border-radius: 2px; }
#campus-region-map { display: flex; height: 450px; height: clamp(405px, 69svh, 560px); overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: var(--field); touch-action: manipulation; }
#campus-map-note { color: var(--muted); font-size: .75rem; line-height: 1.5; word-break: keep-all; }
.entry-guide-link { justify-self: start; color: var(--muted); font-size: .8125rem; text-underline-offset: 3px; }
#campus-map-note[hidden] + .entry-guide-link { display: none; }
.guide-page { width: min(100% - 36px,600px); margin: 40px auto; }
.guide-page h1 { margin: 24px 0 14px; font-size: 1.65rem; }
.guide-page section { margin-block: 24px; }
.guide-page h2 { font-size: 1.1rem; margin-bottom: 6px; }
.guide-page p { color: var(--muted); line-height: 1.6; }
.guide-page a { color: var(--accent); text-underline-offset: 3px; }
.guide-ad { margin-top: 40px; }
.guide-ad:has(ins[data-ad-status="unfilled"]) { display: none; }
.guide-ad ins { display: block; }
.region-map-board { position: relative; flex: 1; min-width: 0; overflow: hidden; }
#region-options { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
#region-options button[data-preview] .region-marker-label { border-color: var(--accent); }
#region-geometry { position: absolute; inset: 0; width: 100%; height: 100%; }
#region-boundaries { transform-origin: 0 0; transition: transform 260ms ease-out; }
#region-boundaries path { fill: var(--region-land); fill-rule: evenodd; stroke: var(--region-edge); stroke-width: .65; stroke-linejoin: round; vector-effect: non-scaling-stroke; transition: fill 150ms ease, stroke 150ms ease; }
#region-boundaries path[data-muted] { fill: var(--region-land-muted); stroke: none; }
#region-boundaries path[data-active] { stroke: none; }
#region-boundaries #region-selection-edge { fill: none; pointer-events: none; }
#region-leaders { pointer-events: none; }
#region-leaders path { fill: none; stroke: var(--region-edge); stroke-width: 1; vector-effect: non-scaling-stroke; }
#region-leaders circle { fill: var(--region-edge); }
#region-footprints path {
  fill: color-mix(in srgb, var(--surface) 65%, var(--accent));
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}
#region-footprints path[data-selected] { fill: var(--accent); }
#region-credit { position: absolute; right: 8px; bottom: 4px; color: var(--muted); font-size: .64rem; }
#region-markers { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
#all-regions { position: absolute; z-index: 1; top: 8px; left: 8px; min-height: 44px; padding-inline: 9px; border: 0; border-radius: 22px; font-size: .8rem; }
#active-region { position: absolute; top: 19px; right: 11px; color: var(--muted); font-size: .75rem; pointer-events: none; }
#region-empty { position: absolute; right: 8px; bottom: 8px; left: 8px; padding: 8px; border-radius: 9px; background: var(--surface); color: var(--muted); text-align: center; font-size: .875rem; }
.region-marker { position: absolute; display: grid; place-items: center; transform: translate(-50%, -50%); min-width: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 22px; background: transparent; pointer-events: auto; }
.region-marker-label { display: block; padding: 4px 8px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); font-size: .78rem; line-height: 1.25; transition: transform 150ms ease, border-color 150ms ease; }
.region-marker:active .region-marker-label { transform: scale(.97); }
.region-marker[aria-pressed="true"] .region-marker-label { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.region-marker-detail { display: block; color: var(--muted); font-size: .7rem; font-weight: 500; }
.region-marker-detail .campus-presence { color: inherit; font-size: inherit; }
.region-marker[aria-pressed="true"] .region-marker-detail { color: inherit; }
@media (hover: hover) and (pointer: fine) {
  #campus-region-map:not([data-detail]) #region-boundaries path { cursor: pointer; }
  #campus-region-map:not([data-detail]) #region-boundaries path:is(:hover, [data-preview]) { fill: color-mix(in srgb, var(--region-land) 78%, var(--accent)); stroke: var(--accent); }
  .region-marker:hover .region-marker-label { transform: translateY(-2px); border-color: var(--accent); }
}
@media (prefers-reduced-motion: reduce) {
  #region-boundaries, #region-boundaries path, .region-marker-label { transition: none; }
}
#campus-results { display: flex; justify-content: space-between; align-items: center; }
#campus-result-count { color: var(--muted); font-size: .875rem; }
#campus-options { display: grid; gap: 8px; }
.campus-option {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 66px;
  padding: 10px 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  cursor: pointer;
}
.campus-option:has(input:checked) { background: var(--selected); border-color: var(--selected-line); }
.campus-option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.campus-option input { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: inherit; }
.campus-emblem { display: block; flex: none; border-radius: 8px; background: #fff; object-fit: contain; }
.campus-name { display: grid; flex: 1; gap: 2px; }
.campus-name strong { font-size: 1rem; line-height: 1.2; }
.campus-detail, #selected-campus, #campus-empty { color: var(--muted); font-size: .875rem; }
.campus-check { display: grid; place-items: center; width: 23px; height: 23px; flex: none; border: 1px solid var(--option-line); border-radius: 50%; color: var(--on-accent); }
.campus-option input:checked ~ .campus-check { border-color: var(--accent); background: var(--accent); }
.campus-option input:checked ~ .campus-check::after { content: ""; width: 8px; height: 4px; border-left: 1.7px solid; border-bottom: 1.7px solid; transform: translateY(-1px) rotate(-45deg); }
.entry-action { display: grid; gap: 10px; margin-top: auto; padding-top: 30px; }
.entry-action button { min-height: 51px; border-radius: 12px; }
.icon-button { display: grid; place-items: center; width: 44px; min-height: 44px; padding: 0; }
.entry-back-row #back-to-campus { margin-left: -8px; border-color: transparent; }
.entry-theme { margin-left: auto; flex: none; }
.theme-icon { width: 16px; height: 16px; border: 1.7px solid currentColor; border-radius: 50%; background: linear-gradient(90deg, currentColor 50%, transparent 50%); }
.map-icon { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.back-icon { position: relative; width: 14px; height: 1.8px; background: currentColor; }
.back-icon::before { content: ""; position: absolute; width: 7px; height: 7px; top: 50%; left: 0; border-left: 1.8px solid currentColor; border-bottom: 1.8px solid currentColor; transform: translateY(-50%) rotate(45deg); }
#join-status { color: var(--muted); font-size: .875rem; }
#join-status:empty { display: none; }

#play { position: relative; width: min(100% - 32px, 1000px); margin: 24px auto; }
.game-header, .game-actions, .controls, #chat { display: flex; align-items: center; gap: 10px; }
.game-header { justify-content: space-between; margin-bottom: 12px; }
.game-identity { display: grid; min-width: 0; gap: 4px; }
.game-brand { gap: 7px; font-size: 1.15rem; }
.game-brand .power-mark { width: 26px; height: 26px; border-radius: 8px; }
.game-brand .power-mark::before { width: 10px; height: 10px; margin-top: 2px; border-width: 1.6px; }
.game-brand .power-mark::after { top: 6px; height: 6px; width: 1.6px; }
#current-campus { color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; }
.game-actions { flex-shrink: 0; }
#count { display: flex; align-items: center; gap: 6px; padding-inline: 4px; color: var(--muted); font-size: .875rem; white-space: nowrap; }
#count::before { content: ""; width: 7px; height: 7px; background: var(--accent); border-radius: 50%; }
.more-icon { width: 3px; height: 3px; background: currentColor; border-radius: 50%; box-shadow: -5px 0 currentColor, 5px 0 currentColor; }
.stage { position: relative; height: clamp(390px, 73dvh, 730px); border-radius: 14px; overflow: hidden; background: #9fb87d; }
canvas { display: block; }
#map { width: 100%; height: 100%; }
#tap-hint { display: none; }
.controls { justify-content: space-between; margin-top: 10px; }
.hint { color: var(--muted); font-size: .875rem; }
kbd { padding: 3px 6px; border-radius: 4px; background: var(--field); color: var(--ink); font: inherit; }
#chat { flex: 1; justify-content: flex-end; }
#message { width: min(100%, 340px); min-height: 42px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--field); }
footer { margin: 10px 0; font-size: .75rem; color: var(--muted); }
footer a { color: inherit; }
dialog { width: min(720px, 96vw); max-height: 91dvh; padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); }
dialog::backdrop { background: #0008; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.dialog-head h2 { font-size: 1.2rem; }
#overview { width: auto; max-width: 100%; max-height: 72dvh; height: auto; margin: auto; border-radius: 10px; }
#menu-dialog { width: min(330px, 92vw); }
.menu-actions { display: grid; gap: 8px; }
.menu-actions button { text-align: left; background: var(--field); border-color: transparent; }

@media (prefers-reduced-motion: no-preference) {
  :root, button, input, dialog, .search-field, #campus-region-map, .campus-option,
  .game-header, #chat, .brand-accent, .power-mark, #current-campus, #count {
    transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease;
  }
}

@media (max-width: 600px), (pointer: coarse) {
  .entry-page { min-height: 480px; margin-block: 0; padding-block: 6px 8px; }
  body.in-campus { overflow: hidden; overscroll-behavior: none; }
  #play { position: absolute; inset: var(--viewport-top, 0px) 0 auto; width: 100%; height: var(--viewport-height, 100dvh); margin: 0; overflow: hidden; isolation: isolate; }
  .stage { height: 100%; border-radius: 0; }
  #map { touch-action: none; }
  .game-header {
    position: absolute;
    inset: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) auto max(8px, env(safe-area-inset-left));
    z-index: 1;
    gap: 4px;
    margin: 0;
    padding: 5px 5px 5px 10px;
    border: 1px solid var(--hud-line);
    border-radius: 14px;
    background: var(--hud);
    pointer-events: none;
  }
  .game-brand { font-size: 1rem; }
  #current-campus { font-size: .72rem; }
  .game-actions { gap: 3px; }
  #count { font-size: .75rem; }
  #count::before { display: none; }
  .game-actions button { min-height: 44px; padding-inline: 7px; pointer-events: auto; }
  .game-actions .icon-button { padding: 0; }
  .controls { position: absolute; inset: auto max(9px, env(safe-area-inset-right)) calc(19px + env(safe-area-inset-bottom)) max(9px, env(safe-area-inset-left)); z-index: 1; margin: 0; pointer-events: none; }
  .hint { display: none; }
  #chat { width: 100%; padding: 5px; gap: 6px; border: 1px solid var(--hud-line); border-radius: 15px; background: var(--hud); pointer-events: auto; }
  #message { width: auto; flex: 1; }
  footer { position: absolute; z-index: 2; inset: auto max(10px, env(safe-area-inset-right)) max(3px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); margin: 0; font-size: .65rem; color: var(--map-credit); text-shadow: 0 1px var(--map-credit-shadow), 0 -1px var(--map-credit-shadow); pointer-events: none; }
  footer a { pointer-events: auto; }
  #tap-hint:not([hidden]) { display: block; position: absolute; left: 50%; bottom: calc(99px + env(safe-area-inset-bottom)); transform: translateX(-50%); padding: 6px 11px; border-radius: 20px; background: var(--hud); color: var(--ink); font-size: .85rem; white-space: nowrap; pointer-events: none; }
}
@media (max-width: 600px) {
  .entry-page { min-height: max(400px, calc(100svh - 32px)); padding-inline: 7px; }
  #campus-region-map { margin-inline: -11px; }
}
@media (max-width: 355px) {
  .region-marker-label { padding-inline: 6px; }
  .campus-option { gap: 7px; padding-inline: 8px; }
}

.campus-presence {
  color: var(--muted);
  font-size: .75rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  margin-inline-start: auto;
}
