@import url('assets/fonts/home-serif.css');

.sd-game, .sd-dialog {
  color-scheme: dark;
  --ink: #112c31;
  --deep: #0b2025;
  --panel: #16373b;
  --paper: #fff1d1;
  --muted: #a6b9b1;
  --gold: #f6cb70;
  --line: #52645a;
  color: var(--paper);
  font: 15px/1.5 system-ui, "Microsoft YaHei", sans-serif;
}
:is(.sd-game, .sd-dialog) button {
  font: inherit; color: inherit; min-height: 44px; border: 1px solid var(--line); border-radius: 4px;
  background: #1a4246; cursor: pointer; touch-action: manipulation;
}
:is(.sd-game, .sd-dialog) button:disabled { opacity: .48; cursor: default; }
:is(.sd-game, .sd-dialog) button:is(:hover, :active):enabled { border-color: var(--gold); }
:is(.sd-game, .sd-dialog) :is(button,a,canvas):focus-visible { outline: 2px solid #fff2a1; outline-offset: 3px; }

.sd-layout {
  width: 100%; max-width: 900px; margin: 0 auto; padding: clamp(24px, 4vw, 46px) clamp(16px, 4vw, 30px) 40px;
  flex: 1;
}
.sd-heading { margin: 0 auto 24px; text-align: center; }
.sd-heading a { color: var(--blue); font-size: 13px; }
.sd-heading h1 { margin: 4px 0; font: 700 clamp(29px, 5vw, 43px)/1.26 var(--serif); }
.sd-heading p { margin: 0; color: var(--muted); font-size: 14px; }
.sd-game { width: 100%; max-width: 460px; margin: auto; }
.sd-chart {
  --vista: none;
  padding: clamp(18px, 3vw, 30px); border: 1px solid #a2915d; border-radius: 8px;
  background: linear-gradient(#102d348f, #142f35f5 67%), var(--vista) center top / cover no-repeat, var(--panel);
  box-shadow: 0 12px 30px #0e2b3929;
}
.sd-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-bottom: 16px; }
.sd-tabs button[aria-pressed="true"], .sd-stages button[aria-pressed="true"] {
  color: var(--ink); background: var(--gold); border-color: var(--gold); font-weight: 700;
}
.sd-campaign { border-top: 1px solid var(--line); min-height: 164px; }
.sd-sector { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; gap: 8px; align-items: center; text-align: center; padding: 14px 0 12px; }
.sd-sector button { font-size: 24px; line-height: 1; }
.sd-sector h2 { font-size: 17px; line-height: 1.35; margin: 0; color: var(--paper); }
.sd-sector p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.sd-stages { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.sd-stages button { font-weight: 650; }
.sd-stages button.is-cleared::after { content: ' ✓'; font-size: 11px; }
.sd-stages button.is-node { border-bottom-color: var(--gold); }
.sd-difficulty { margin-top: 14px; margin-bottom: 0; }
.sd-stages button.is-elite { grid-column: 1 / -1; min-height: 64px; border-color: #e39b67; font-size: 19px; }
:is(.sd-game, .sd-dialog) .sd-primary {
  display: inline-flex; justify-content: center; align-items: center; width: 100%; min-height: 48px;
  background: var(--gold); color: #182c2e; border-color: #ffdc94; font-weight: 800;
}
.sd-endless { padding: 18px 0; }
.sd-endless p, .sd-note { font-size: 12px; color: #bdcbc0; margin: 9px 0 13px; }
.sd-note:empty { display: none; }
.sd-chart-tools { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 10px; }
.sd-chart-tools button { padding: 0 12px; font-size: 13px; }
.sd-chart-tools a { min-height: 44px; display: inline-flex; align-items: center; color: var(--paper); font-size: 13px; }
#saveNote { margin: 10px 0 0; text-align: center; }

.sd-ship { display: grid; justify-items: center; min-width: 0; }
.sd-ship:fullscreen { place-items: center; background: var(--deep); }
.sd-ship:fullscreen .sd-theater { width: min(calc(100vw - 12px), calc((100dvh - 12px) * .5625)); }
.sd-theater {
  isolation: isolate; position: relative; width: min(100%, 436px, max(235px, calc((100svh - 100px) * .5625)));
  aspect-ratio: 9 / 16; overflow: hidden; border-radius: 7px;
  outline: 1px solid #b79b63; box-shadow: 0 0 0 5px #17343a, 0 14px 46px #0007;
  background: #51402f;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-user-drag: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: contain;
}
#shipCanvas { display: block; width: 100%; height: 100%; touch-action: none; }
.sd-top {
  position: absolute; inset: 0 0 auto; padding: 9px 12px 16px;
  background: linear-gradient(#091b22ee 55%, #091b2200);
  pointer-events: none; font-size: 12px; font-variant-numeric: tabular-nums;
}
.sd-top button { min-height: 36px; padding: 2px 11px; font-size: 12px; pointer-events: auto; }
.sd-hud-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.sd-hud-row > div { min-width: 0; display: flex; align-items: baseline; gap: 8px; }
#waveLabel { font-size: 15px; color: var(--gold); }
#waveTimer { color: var(--muted); }
.sd-meter-row { display: grid; grid-template-columns: 35px 1fr minmax(27px,auto); gap: 7px; align-items: center; margin: 4px 0; }
.sd-meter-row progress { width: 100%; height: 6px; border: 0; border-radius: 9px; overflow: hidden; background: #17282d; color: #92e6ab; }
.sd-meter-row progress::-webkit-progress-bar { background: #29464d; }
.sd-meter-row progress::-webkit-progress-value { background: #8ce4aa; }
.sd-meter-row progress::-moz-progress-bar { background: #8ce4aa; }
#xp::-webkit-progress-value { background: #52dcc9; }
#xp::-moz-progress-bar { background: #52dcc9; }
.sd-bottom {
  position: absolute; inset: auto 10px 7px; display: flex; align-items: end; gap: 7px;
  justify-content: space-between; pointer-events: none; padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sd-loadout { display: flex; gap: 3px; min-width: 0; padding: 3px; border-radius: 4px; background: #11282bd9; }
.sd-loadout:empty { display: none; }
.sd-loadout-count{align-self:center;padding:0 3px;font:700 11px/1.2 system-ui;color:#ffe9af}
.sd-loadout{max-width:calc(100% - 72px);flex-wrap:wrap;row-gap:4px;max-height:96px;overflow:hidden;align-content:flex-end}
.sd-dialog button{touch-action:manipulation}
.sd-gun { display: grid; justify-items: center; font: 9px/1.15 ui-monospace, monospace; color: var(--gold); }
.sd-gun .sd-icon { width: clamp(20px, 4vmin, 27px); }
#activeSkill {
  pointer-events: auto; min-width: 59px; min-height: 63px; flex: none; display: grid; justify-items: center;
  padding: 4px; background: #142d36ed; border: 2px solid var(--gold); border-radius: 8px;
  color: #ffe9af; font-size: 10px; line-height: 1.25;
}
#activeSkill .sd-icon { width: 39px; }
#activeSkill:disabled { opacity: .84; border-color: #718c87; color: #b9c8c2; }
.sd-icon {
  display: block; flex: none; width: 40px; aspect-ratio: 1; background-size: 300% 300%;
  background-image: url('assets/ship-defense/art-v1/ability-icons.png'); image-rendering: pixelated;
}
.sd-fallback {
  margin-top: 14px; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px 14px;
}
.sd-fallback p { margin: 0; }
.sd-fallback button { padding-inline: 12px; }

.sd-dialog {
  width: min(calc(100vw - 28px), 420px); max-width: none; max-height: calc(100dvh - 28px);
  border-radius: 9px; padding: 0; border: 2px solid #bda267; background: var(--ink);
  color: var(--paper); box-shadow: 0 22px 58px #010b11b0;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; overscroll-behavior: contain;
}
.sd-dialog::backdrop { background: #07171bbe; }
.sd-panel { padding: 21px; }
.sd-panel h2 { margin: 0 0 5px; color: var(--gold); font: 750 27px/1.2 "Noto Serif SC", "Microsoft YaHei", serif; }
.sd-panel p { margin: 0 0 17px; color: #d1ded4; font-size: 13px; white-space: pre-line; }
.sd-options, .sd-menu-actions { display: grid; gap: 8px; }
.sd-menu-actions:not(:empty) { margin-top: 12px; }
.sd-dialog .sd-card {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  text-align: left; min-height: 68px; background: #214650; border-color: #69847a;
}
.sd-card b, .sd-card small, .sd-card em { display: block; }
.sd-card em { color: var(--gold); font-size: 10px; font-style: normal; }
.sd-card small { color: #cfddd6; line-height: 1.45; }
.sd-card .sd-icon { width: 43px; }
.sd-menu-actions button { min-height: 45px; }
.sd-dialog .sd-setting { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; }
.sd-setting span { color: var(--muted); }
.sd-setting[aria-pressed="true"] span { color: var(--gold); }
.sd-manual { margin-top: clamp(32px, 6vw, 55px); padding-top: 22px; border-top: 1px solid var(--line); }
.sd-manual h2 { margin: 0 0 12px; font-size: 25px; }
.sd-manual dl { margin: 14px 0; display: grid; grid-template-columns: max-content 1fr; gap: 10px 14px; }
.sd-manual dt { font-weight: 700; }
.sd-manual dd { margin: 0; }
.sd-manual p, .sd-manual dl { font-size: 14px; }
.sd-credits { margin-top: 18px; font-size: 12px; color: var(--muted); }
.sd-credits a { color: var(--blue); text-decoration: underline; }
.sd-credits summary { cursor: pointer; }
.sd-credits p { margin: 6px 0 0; }

@media (max-width: 670px) {
  .sd-game { max-width: 435px; }
  .sd-page.in-battle { overflow: hidden; }
  .sd-page.in-battle :is(.site-masthead,.sd-heading,.sd-manual,.site-footer) { display: none; }
  .sd-page.in-battle .sd-layout { padding: 0; }
  .sd-page.in-battle .sd-game {
    display: grid; max-width: none;
    height: 100dvh; padding: max(4px,env(safe-area-inset-top)) max(5px,env(safe-area-inset-right))
      max(4px,env(safe-area-inset-bottom)) max(5px,env(safe-area-inset-left)); place-items: center;
  }
  .sd-page.in-battle .sd-ship { width: 100%; }
  .sd-page.in-battle .sd-theater { width: min(100%, 485px, calc((100dvh - 14px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * .5625)); }
  .sd-page.in-battle .sd-bottom { padding-bottom: 0; }
}
@media (max-width: 350px) {
  .sd-dialog .sd-card { min-height: 55px; }
  .sd-panel { padding: 15px; }
}

.sd-resource-loader {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
  padding: 24px; background: radial-gradient(ellipse at 50% 35%, #174b52, #071e2b 75%);
  color: #fff0cc; font: 15px/1.6 system-ui, 'Microsoft YaHei', sans-serif;
}
.sd-resource-loader[hidden] {display: none;}
.sd-resource-card {width: min(100%, 360px); text-align: center;}
.sd-resource-card h1 {margin: 0; font-size: clamp(27px, 7vw, 36px); color: #f5ce79;}
.sd-resource-card > p {margin: 12px 0; color: #cfddd6;}
.sd-resource-progress {display: flex; align-items: center; gap: 12px; margin: 28px 0 12px;}
.sd-resource-progress progress {width: 100%; min-width: 0; height: 16px; appearance: none; border: 1px solid #be9853; border-radius: 9px; overflow: hidden; background: #09222d;}
.sd-resource-progress progress::-webkit-progress-bar {background: #09222d;}
.sd-resource-progress progress::-webkit-progress-value {background: linear-gradient(90deg, #c88c37, #ffe49a); border-radius: 9px;}
.sd-resource-progress progress::-moz-progress-bar {background: #f2c56e; border-radius: 9px;}
.sd-resource-progress b {min-width: 44px; font-variant-numeric: tabular-nums; color: #ffe49a;}
#resourceStatus {font-size: 12px; min-height: 20px;}
#retryResources {margin-top: 15px; padding: 10px 24px; border: 1px solid #e8bf6a; border-radius: 6px; background: #efc36e; color: #302718; font: inherit; cursor: pointer;}
