:root {
  color-scheme: dark;
  font-family: "Yu Gothic UI", Meiryo, sans-serif;
  background: #111714;
  color: #e6eee8;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 50% -15%, rgba(102, 147, 111, .16), transparent 55%),
    #111714;
}

.audio-start-screen {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
  color: #fff;
  font: 500 clamp(18px, 3vw, 30px) Consolas, monospace;
  letter-spacing: .04em;
  cursor: pointer;
  transition: color 1000ms ease, background-color 2000ms ease;
}
.audio-start-screen .start-warning {
  max-width: min(760px, calc(100vw - 40px));
  color: #c8c8c8;
  font: 400 clamp(13px, 1.8vw, 17px)/1.6 "Yu Gothic UI", Meiryo, sans-serif;
  letter-spacing: .02em;
  white-space: pre-line;
}
.audio-start-screen:hover { color: #e7e7e7; }
.audio-start-screen.fade-text { color: transparent; cursor: default; }
.audio-start-screen.fade-text .start-warning { color: transparent; }
.audio-start-screen.reveal { background-color: transparent; }
.audio-start-screen:focus-visible { outline: 2px solid #fff; outline-offset: -8px; }
.audio-start-screen[hidden] { display: none; }

.title-screen {
  position: fixed;
  z-index: 20;
  inset: 0;
  overflow: hidden;
  background: #090c0d;
  opacity: 1;
  transition: opacity 700ms ease;
}
.title-screen[hidden] { display: none; }
.title-screen.fade-out { opacity: 0; pointer-events: none; }
.title-background, .title-shade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.title-background {
  object-fit: cover;
  object-position: center;
  opacity: 1;
}
.title-shade {
  background: linear-gradient(90deg, transparent 28%, rgba(8, 12, 15, .12) 48%, rgba(8, 12, 15, .68) 100%);
}
.title-menu {
  position: absolute;
  top: 50%;
  right: clamp(24px, 7vw, 112px);
  width: min(48vw, 620px);
  transform: translateY(-50%);
  color: #fff5de;
  text-shadow: 0 3px 14px #000, 0 1px 3px #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 600ms ease;
}
.title-screen.menu-visible .title-menu { opacity: 1; pointer-events: auto; }
.title-screen.title-load-open .title-menu { pointer-events: none; }
.title-screen.title-rule-open .title-menu { pointer-events: none; }
.stage-debug-menu {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: min(420px, calc(100vw - 32px));
  padding: 24px;
  transform: translate(-50%, -50%);
  border: 1px solid #b6aa78;
  border-radius: 6px;
  background: rgba(13, 20, 17, .96);
  box-shadow: 0 12px 40px #000c;
  color: #f1ead7;
  text-align: center;
}
.stage-debug-menu[hidden] { display: none; }
.stage-debug-menu [hidden] { display: none; }
.stage-debug-menu h2 { margin: 0 0 8px; color: #f1d978; }
.stage-debug-menu p { margin: 0 0 16px; color: #b8c3b9; font-size: 13px; }
.stage-debug-options { display: grid; gap: 8px; margin-bottom: 14px; }
.stage-debug-menu button, .stage-preview-banner button {
  min-height: 40px;
  border: 1px solid #637261;
  border-radius: 4px;
  background: #202b22;
  color: #f1ead7;
  font: 600 15px "Yu Gothic UI", Meiryo, sans-serif;
  cursor: pointer;
}
.stage-debug-menu button:hover, .stage-debug-menu button:focus-visible,
.stage-debug-menu button.selected, .stage-preview-banner button:hover {
  border-color: #f1d978;
  color: #f1d978;
  outline: 2px solid #f1d978;
  outline-offset: 2px;
}
.stage-debug-menu #stage-debug-status { min-height: 1.4em; margin: 8px 0; color: #ffb7a8; }
.intro-event {
  position: fixed;
  z-index: 25;
  inset: 0;
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  padding: 0;
  border: 0;
  background: #000;
  opacity: 1;
  transition: opacity 700ms ease;
}
.intro-event[hidden] { display: none; }
.intro-event.fade-out { opacity: 0; }
.intro-event > img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 2000ms ease;
}
.intro-event.show-image > img { opacity: 1; }
.battle-message-panel {
  --portrait-width: 120px;
  --portrait-gap: 40px;
  box-sizing: border-box;
  width: 100%;
  height: clamp(160px, 19vh, 180px);
  margin: 0 0 18px;
}
.battle-message-panel[hidden] { display: block; visibility: hidden; pointer-events: none; }
.battle-condition-panel {
  box-sizing: border-box;
  height: 100%;
  overflow-y: auto;
  padding: 10px 14px;
  border: 1px solid rgba(219, 224, 226, .45);
  border-radius: 5px;
  background: linear-gradient(120deg, rgba(8, 13, 18, .88), rgba(12, 20, 26, .76));
  color: #f4f1e8;
  font: 500 clamp(12px, 1.35vw, 15px)/1.55 "Yu Gothic UI", Meiryo, sans-serif;
}
.battle-condition-panel[hidden] { display: none; }
.battle-condition-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.battle-condition-group h2 { margin: 0 0 4px; color: #f1d978; font-size: 1em; }
.battle-condition-group ul { margin: 0; padding-left: 1.5em; }
.battle-condition-group p { margin: 0; }
.battle-condition-group li { padding-left: .15em; }
.battle-message-panel .story-window { position: relative; inset: auto; width: 100%; height: 100%; max-height: none; margin: 0; padding-top: 8px; padding-bottom: 6px; }
.battle-message-panel .battle-message-layout { display: flex; align-items: flex-end; gap: var(--portrait-gap); }
.battle-message-panel .battle-message-content { display: flex; min-width: 0; flex: 1; flex-direction: column; }
.battle-message-panel .story-portrait { display: block; width: var(--portrait-width); height: 136px; flex: 0 0 var(--portrait-width); object-fit: contain; object-position: center bottom; transform: translateY(7px); }
.battle-message-panel .story-portrait[hidden] { display: none; }
.intro-event:not(.battle-event):not(.custom-macro-message) .story-window:not(.with-portrait) .battle-message-layout,
.intro-event:not(.battle-event):not(.custom-macro-message) .story-window:not(.with-portrait) .battle-message-content { display: contents; }
.intro-event.custom-macro-message { --portrait-width: 120px; --portrait-gap: 40px; }
.battle-message-panel.inter-story-panel {
  position: fixed;
  z-index: 26;
  right: clamp(16px, 5vw, 72px);
  bottom: clamp(16px, 4vh, 40px);
  left: clamp(16px, 5vw, 72px);
  width: auto;
  height: clamp(160px, 19vh, 180px);
  margin: 0;
}
.intro-event.custom-macro-message .story-window {
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: clamp(160px, 19vh, 180px);
  max-height: none;
  margin: 0;
  padding: 8px 16px 6px;
}
.intro-event.custom-macro-message .battle-message-layout { display: flex; align-items: flex-end; gap: var(--portrait-gap); }
.intro-event.custom-macro-message .battle-message-content { display: flex; min-width: 0; flex: 1; flex-direction: column; }
.intro-event.custom-macro-message .story-portrait {
  display: block;
  width: var(--portrait-width);
  height: 136px;
  flex: 0 0 var(--portrait-width);
  object-fit: contain;
  object-position: center bottom;
  transform: translateY(7px);
}
.intro-event.custom-macro-message .story-portrait[hidden] { display: none; }
.intro-event.custom-macro-message .story-text { flex: 0 0 3.6em; height: 3.6em; min-height: 3.6em; max-height: 3.6em; }
/* Bust-up dialogue (MES 名前 PCnn) shares the battle message coordinates. */
.story-window.with-portrait .battle-message-layout {
  display: grid;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  grid-template-columns: var(--portrait-width, 120px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  column-gap: var(--portrait-gap, 40px);
  align-items: stretch;
}
.story-window .battle-message-layout {
  display: grid;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0;
  grid-template-columns: var(--portrait-width, 120px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  column-gap: var(--portrait-gap, 40px);
  align-items: stretch;
}
.story-window .battle-message-content {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-self: start;
  padding-top: 14px;
}
.story-window .story-portrait { grid-column: 1; grid-row: 1; }
.story-window.with-portrait { box-sizing: border-box; padding: 8px clamp(16px, 3vw, 36px) 6px; }
.intro-event.custom-macro-message .story-window.with-portrait { padding: 8px clamp(16px, 3vw, 36px) 6px; }
.story-window.with-portrait .story-portrait {
  grid-column: 1;
  grid-row: 1;
  align-self: start;
  justify-self: start;
}
.story-window .story-speaker:not(:empty) {
  align-self: flex-start;
  justify-self: start;
  margin: 0 0 8px;
}
.story-window.with-portrait .story-text {
  flex: 0 0 3.6em;
  height: 3.6em;
  min-height: 3.6em;
  max-height: 3.6em;
  width: 100%;
  margin: 0;
}
.story-window.with-portrait .story-start {
  position: absolute;
  right: 24px;
  bottom: 10px;
  margin: 0;
}
.story-speaker:empty { display: none; }
.story-speaker:not(:empty) {
  align-self: flex-start;
  margin: -4px 0 8px;
  padding: 2px 12px;
  border: 1px solid rgba(219, 224, 226, .62);
  border-radius: 3px;
  background: rgba(8, 13, 18, .94);
  color: #ffe5a3;
  font: 700 clamp(14px, 1.5vw, 18px)/1.6 "Yu Gothic UI", Meiryo, sans-serif;
}
.story-window.system-message:not(.with-portrait) .battle-message-layout { display: grid; }
.story-window.prologue-message .battle-message-layout,
.story-window.prologue-message .battle-message-content { display: contents; }
.story-window.character-message:not(.with-portrait) .battle-message-layout { display: grid; }
.story-window.system-message .story-text {
  width: 100%;
  margin-top: clamp(26px, calc(2.4vw + 4px), 33px);
  color: #ffe45c;
  text-align: left;
}
.story-window.prologue-message .story-text {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  max-height: none;
  text-align: left;
}
.story-window {
  position: absolute;
  z-index: 1;
  right: clamp(16px, 5vw, 72px);
  bottom: clamp(16px, 4vh, 40px);
  left: clamp(16px, 5vw, 72px);
  display: flex;
  max-height: min(46vh, 390px);
  flex-direction: column;
  padding: clamp(14px, 2.4vw, 28px) clamp(16px, 3vw, 36px) 12px;
  border: 1px solid rgba(219, 224, 226, .62);
  border-radius: 5px;
  background: linear-gradient(120deg, rgba(8, 13, 18, .92), rgba(12, 20, 26, .78));
  box-shadow: 0 8px 32px #0009, inset 0 0 22px #ffffff0a;
  color: #fff;
  text-align: left;
}
.story-window[hidden] { display: none; }
.intro-event:not(.custom-macro-message) .story-window {
  box-sizing: border-box;
  height: max(210px, calc(min(46vh, 390px) - 3.6em));
}
.intro-event:not(.custom-macro-message) .story-text { flex: 1 1 auto; }
.story-text {
  overflow-y: auto;
  min-height: 0;
  color: #f4f1e8;
  font: 500 clamp(14px, 1.65vw, 20px)/1.8 "Yu Gothic UI", Meiryo, sans-serif;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  scrollbar-color: #b3a77b #20282b;
}
.battle-message-panel .story-text {
  flex: 0 0 3.6em;
  height: 3.6em;
  min-height: 3.6em;
  max-height: 3.6em;
}
@media (max-width: 600px) {
  .battle-message-panel { --portrait-width: min(100px, 30vw); --portrait-gap: 10px; }
  .battle-message-panel { height: clamp(220px, 30vh, 250px); }
  .battle-condition-panel { padding: 7px 10px; }
  .battle-condition-columns { grid-template-columns: 1fr; gap: 6px; }
  .battle-message-panel .story-portrait { height: min(113px, 34vw); }
  .intro-event.custom-macro-message { --portrait-width: min(100px, 30vw); --portrait-gap: 10px; }
  .battle-message-panel.inter-story-panel { height: clamp(220px, 30vh, 250px); }
  .intro-event.custom-macro-message .story-window { height: clamp(220px, 30vh, 250px); }
  .intro-event.custom-macro-message .story-portrait { height: min(113px, 34vw); }
  .battle-message-panel .story-text,
  .intro-event.custom-macro-message .story-text {
    flex-basis: 7.2em;
    height: 7.2em;
    min-height: 7.2em;
    max-height: 7.2em;
  }
  .story-window.system-message .story-text { margin-top: 0; }
  .story-window.with-portrait .story-text {
    flex-basis: 7.2em;
    height: 7.2em;
    min-height: 7.2em;
    max-height: 7.2em;
  }
}
.story-skip, .story-start {
  align-self: flex-end;
  margin-top: 4px;
  padding: 4px 8px;
  border: 0;
  background: transparent;
  color: #ffe5a3;
  font: 700 clamp(16px, 1.8vw, 22px) "Yu Gothic UI", Meiryo, sans-serif;
  letter-spacing: .08em;
  text-shadow: 0 2px 8px #000;
  cursor: pointer;
}
.story-skip { font-size: clamp(12px, 1.3vw, 16px); }
.story-skip[hidden] { display: none; }
/* Keep the Event window's skip row reserved when Continue replaces it. */
.intro-event:not(.battle-event) .story-skip[hidden] { display: block; visibility: hidden; }
.story-start:disabled { visibility: hidden; }
.story-start:not(:disabled) { animation: story-start-blink 1s steps(2, start) infinite; }
.story-start:focus-visible { outline: 2px solid #ffe5a3; outline-offset: 3px; }
@keyframes story-start-blink { to { opacity: .35; } }
.title-menu h1 {
  margin: 0 0 clamp(28px, 5vh, 52px);
  color: #fff0ce;
  font-size: clamp(26px, 3.1vw, 42px);
  font-weight: 800;
  letter-spacing: .04em;
  white-space: nowrap;
}
.title-options { display: flex; flex-direction: column; align-items: flex-start; gap: 9px; }
.title-options button {
  position: relative;
  min-width: min(100%, 330px);
  padding: 12px 20px 12px 28px;
  border: 1px solid transparent;
  background: transparent;
  color: #f2e9d6;
  font: 700 clamp(16px, 2vw, 23px) "Yu Gothic UI", Meiryo, sans-serif;
  letter-spacing: .05em;
  text-align: left;
  text-shadow: inherit;
  cursor: pointer;
}
.title-options button.selected {
  border-color: rgba(240, 209, 139, .7);
  background: rgba(18, 23, 27, .68);
  color: #ffe2a5;
  box-shadow: 0 4px 20px #0005;
}
.title-options button.selected::before {
  position: absolute;
  left: 9px;
  content: "▶";
  color: #f4c56b;
}
.title-options button:focus-visible { outline: 2px solid #ffe2a5; outline-offset: 2px; }

.game-shell {
  width: min(100% - 40px, 1080px);
  margin: 0 auto;
  padding: 24px 0 28px;
}

.game-header, .status {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.game-header { margin-bottom: 16px; }
.map-zoom-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin: -8px 0 8px;
}
.map-cursor-position { margin-right: auto; color: #95a198; font: 11px Consolas, monospace; letter-spacing: .06em; }
.map-cursor-position strong { margin-left: 6px; color: #e9d783; font-weight: 500; }
.map-zoom-controls button {
  min-width: 36px;
  min-height: 32px;
  padding: 2px 8px;
  border: 1px solid #637261;
  border-radius: 4px;
  background: #202a23;
  color: #e6eee8;
  font: 700 20px/1 "Yu Gothic UI", Meiryo, sans-serif;
  cursor: pointer;
}
.map-zoom-controls button:hover:not(:disabled),
.map-zoom-controls button:focus-visible { border-color: #e3cb75; color: #ffe5a3; }
.map-zoom-controls button:disabled { opacity: .45; cursor: default; }
.stage-preview-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid #817746;
  border-radius: 4px;
  background: #24291e;
  color: #d8dfd6;
  font-size: 13px;
}
.stage-preview-banner[hidden] { display: none; }
.stage-preview-banner strong { color: #f1d978; }
.stage-preview-banner span { flex: 1; }
.stage-preview-banner button { min-height: 34px; padding: 4px 12px; font-size: 13px; }
.eyebrow {
  margin: 0 0 5px;
  color: #91aa98;
  font: 500 10px Consolas, monospace;
  letter-spacing: .2em;
}
h1 { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: .02em; }
.help { margin: 0; color: #9eaaa1; font-size: 12px; }

.map-frame {
  position: relative;
  width: 100%;
  aspect-ratio: var(--map-frame-aspect, 4 / 3);
  overflow: visible;
  margin-bottom: 18px;
  border: 1px solid #37463b;
  border-radius: 5px;
  background: #25382e;
  box-shadow: 0 18px 60px #0005, 0 0 0 5px #1a231d;
}
.map-frame > canvas { width: 100%; height: 100%; }
.passability-legend {
  position: absolute;
  z-index: 3;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 12px;
  padding: 6px 9px;
  border: 1px solid #ffffff45;
  border-radius: 4px;
  background: #101710d9;
  color: #fff;
  font: 600 12px "Yu Gothic UI", Meiryo, sans-serif;
  pointer-events: none;
}
.passability-legend[hidden] { display: none; }
.passability-legend span { display: inline-flex; align-items: center; gap: 5px; }
.passability-swatch { display: inline-block; width: 13px; height: 13px; border: 1px solid #ffffffa0; border-radius: 2px; }
.passability-swatch.passable { background: rgba(73, 220, 115, .5); }
.passability-swatch.impassable { background: rgba(240, 68, 68, .65); }
.map-scrollbar {
  position: absolute;
  z-index: 4;
  border: 1px solid #87918299;
  border-radius: 8px;
  background: #0c120e99;
  touch-action: none;
  user-select: none;
}
.map-scrollbar:focus-visible { outline: 2px solid #fff1a1; outline-offset: 2px; }
.map-scrollbar span {
  position: absolute;
  display: block;
  border: 1px solid #e8e0b5;
  border-radius: 8px;
  background: #d9d1a9d9;
}
.map-scrollbar-x { right: 20px; bottom: -16px; left: 4px; height: 12px; }
.map-scrollbar-x span { top: 0; bottom: 0; }
.map-scrollbar-y { top: 4px; right: -16px; bottom: 20px; width: 12px; }
.map-scrollbar-y span { right: 0; left: 0; }

.unit-command {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  min-width: 132px;
  overflow: hidden;
  border: 1px solid #f1d978;
  border-radius: 4px;
  background: #202b22;
  box-shadow: 0 4px 14px #0008;
}
.unit-command[hidden] { display: none; }
.unit-command button {
  padding: 7px 12px;
  border: 0;
  background: transparent;
  color: #f1d978;
  font: 600 14px "Yu Gothic UI", Meiryo, sans-serif;
  white-space: nowrap;
  cursor: pointer;
}
.unit-command button + button { border-top: 1px solid #485343; }
.unit-command button:disabled { opacity: .58; cursor: default; }
.unit-command button:hover, .unit-command button:focus-visible {
  background: #f1d978;
  color: #202b22;
  outline: none;
}
.unit-command button:disabled:hover { background: transparent; color: #f1d978; }
.precision-confirm-command { min-width: 252px; }
.precision-confirm-message {
  padding: 8px 10px;
  border-bottom: 1px solid #485343;
  color: #f3ead0;
  font: 600 13px/1.5 "Yu Gothic UI", Meiryo, sans-serif;
  white-space: normal;
}
.save-slot-dialog {
  position: absolute;
  z-index: 5;
  top: 50%;
  left: 50%;
  width: min(560px, calc(100% - 24px));
  height: min(80vh, 520px);
  max-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translate(-50%, -50%);
  padding: 16px;
  border: 1px solid #f1d978;
  border-radius: 5px;
  background: #1a241eef;
  color: #f2e9d6;
  box-shadow: 0 10px 36px #000b;
}
.save-slot-dialog.floating-save-dialog {
  position: fixed;
  z-index: 31;
}
.save-slot-dialog[hidden] { display: none; }
.save-slot-dialog h2 { flex: 0 0 auto; margin: 0 0 12px; font-size: 17px; }
.save-slot-dialog.delete-mode { border-color: #e58a7a; }
.save-slot-dialog.delete-mode h2 { color: #ffb7a8; }
.save-slot-dialog.delete-mode li button:not(:disabled) { border-color: #9d554a; }
.save-slot-dialog.delete-mode li button:hover:not(:disabled),
.save-slot-dialog.delete-mode li button:focus-visible { border-color: #ff8c78; color: #ffd4ca; }
.save-slot-dialog ol { display: grid; flex: 1 1 auto; grid-template-columns: 1fr 1fr; align-content: start; gap: 6px; min-height: 0; margin: 0 0 14px; padding: 0 4px 0 0; overflow-y: auto; overscroll-behavior: contain; list-style: none; }
.save-slot-dialog li button { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; align-items: center; width: 100%; min-height: 48px; padding: 5px 7px; border: 1px solid #637261; border-radius: 3px; background: #202b22; color: #c8d1c5; font: 11px/1.35 "Yu Gothic UI", Meiryo, sans-serif; text-align: left; cursor: pointer; }
.save-slot-dialog li button:hover:not(:disabled), .save-slot-dialog li button:focus-visible { border-color: #f1d978; color: #ffe2a5; outline: none; }
.save-slot-dialog li button:disabled { opacity: .72; cursor: default; }
.save-slot-dialog li button strong { grid-column: 1; grid-row: 1; color: #f1d978; white-space: nowrap; }
.save-slot-dialog li button .save-slot-date { grid-column: 2; grid-row: 1; justify-self: end; white-space: nowrap; }
.save-slot-dialog li button .save-slot-details { grid-column: 1 / -1; grid-row: 2; padding-left: 1em; white-space: nowrap; }
.save-slot-dialog li button .save-slot-empty { grid-column: 1 / -1; grid-row: 2; white-space: nowrap; }
.save-slot-dialog p { flex: 0 0 auto; min-height: 1.4em; margin: 0 0 10px; color: #a9b9ab; font-size: 12px; }
.save-slot-dialog > button { flex: 0 0 auto; width: 100%; padding: 7px; border: 1px solid #637261; border-radius: 4px; background: #29392e; color: #e6eee8; font: 600 13px "Yu Gothic UI", Meiryo, sans-serif; cursor: pointer; }
.save-slot-dialog > button:hover, .save-slot-dialog > button:focus-visible { border-color: #f1d978; color: #f1d978; }
.game-rule-dialog {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, .62);
}
.game-rule-dialog[hidden] { display: none; }
.game-rule-panel {
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  max-height: min(88vh, 820px);
  padding: clamp(16px, 3vw, 28px);
  border: 1px solid #f1d978;
  border-radius: 6px;
  background: #17221ff5;
  color: #f2e9d6;
  box-shadow: 0 12px 44px #000d;
}
.game-rule-panel h2 { margin: 0 0 14px; color: #f1d978; font-size: 20px; }
.game-rule-content {
  overflow: auto;
  min-height: 0;
  padding: 2px 12px 12px 2px;
  line-height: 1.8;
  overscroll-behavior: contain;
}
.game-rule-content h3 { margin: 24px 0 10px; padding-bottom: 7px; border-bottom: 1px solid #8a8050; color: #f1d978; font-size: 23px; line-height: 1.4; }
.game-rule-content h3:first-child { margin-top: 0; }
.game-rule-content h4 { margin: 16px 0 5px; color: #a9d8ac; font-size: 15px; }
.game-rule-content h5 { margin: 12px 0 3px; color: #ffe2a5; font-size: 14px; }
.game-rule-content p { margin: 4px 0 9px; }
.game-rule-content ul { margin: 4px 0 10px; padding-left: 1.5em; }
.game-rule-content li { padding-left: .2em; }
.game-rule-panel > button { flex: 0 0 auto; min-height: 40px; margin-top: 12px; border: 1px solid #637261; border-radius: 4px; background: #29392e; color: #e6eee8; font: 600 14px "Yu Gothic UI", Meiryo, sans-serif; cursor: pointer; }
.game-rule-panel > button:hover, .game-rule-panel > button:focus-visible { border-color: #f1d978; color: #f1d978; outline: none; }
@media (max-width: 560px) {
  .save-slot-dialog ol { grid-template-columns: 1fr; }
}

.unit-status {
  position: absolute;
  z-index: 2;
  min-width: 176px;
  padding: 10px 12px;
  border: 1px solid #8ca18c;
  border-radius: 4px;
  background: #1b2821f2;
  color: #e6eee8;
  font: 12px/1.65 Consolas, "Yu Gothic UI", Meiryo, monospace;
  box-shadow: 0 4px 14px #0008;
  pointer-events: none;
}
.unit-status[hidden] { display: none; }
.unit-status .status-title {
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid #536353;
  color: #f1d978;
  font-weight: 700;
}
.unit-status .status-side { color: #a9b9ab; }
.unit-status .status-detail { padding-left: 1em; }
.debug-panel {
  position: absolute;
  z-index: 8;
  top: 50%;
  left: 50%;
  width: min(340px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow-y: auto;
  padding: 16px;
  transform: translate(-50%, -50%);
  border: 1px solid #f1d978;
  border-radius: 6px;
  background: #17221fee;
  color: #e6eee8;
  box-shadow: 0 8px 28px #000c;
  font: 13px "Yu Gothic UI", Meiryo, sans-serif;
}
.debug-panel[hidden] { display: none; }
.debug-panel h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
  color: #f1d978;
  font-size: 18px;
}
.debug-panel-drag-handle { cursor: move; touch-action: none; user-select: none; }
.debug-panel-drag-handle span { color: #9eae9c; font-size: 10px; font-weight: 400; white-space: nowrap; }
.debug-panel > label { display: grid; grid-template-columns: 1fr 120px; align-items: center; gap: 10px; margin: 7px 0; }
.debug-panel input, .debug-panel select {
  width: 100%;
  min-width: 0;
  padding: 5px 7px;
  border: 1px solid #596b57;
  border-radius: 3px;
  background: #0e1711;
  color: #fff;
  font: inherit;
}
.debug-actions { display: flex; gap: 8px; margin-top: 14px; }
.debug-actions button {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid #879777;
  border-radius: 4px;
  background: #29392e;
  color: #f1d978;
  font: 600 14px "Yu Gothic UI", Meiryo, sans-serif;
  cursor: pointer;
}
.debug-actions button:hover, .debug-actions button:focus-visible { background: #43523b; outline: 1px solid #f1d978; }
.debug-panel p { margin: 10px 0 0; color: #a9b9ab; font-size: 11px; text-align: right; }
.unit-command button.selected {
  background: #f1d978;
  color: #202b22;
}

.attack-message {
  position: absolute;
  z-index: 3;
  top: 16px;
  left: 50%;
  padding: 10px 22px;
  transform: translateX(-50%);
  border: 1px solid #ffb096;
  border-radius: 4px;
  background: #542d2aee;
  color: #ffe2b2;
  font: 800 22px Consolas, monospace;
  letter-spacing: .06em;
  text-shadow: 0 2px 8px #000;
  box-shadow: 0 5px 18px #0008;
  pointer-events: none;
}
.attack-message[hidden] { display: none; }

.phase-announcement {
  position: absolute;
  z-index: 3;
  top: 50%;
  left: 50%;
  padding: 13px 30px;
  transform: translate(-50%, -50%);
  border: 1px solid #d5dfa8;
  border-radius: 5px;
  background: #1d2d25ed;
  color: #edf0bd;
  font: 800 24px "Yu Gothic UI", Meiryo, sans-serif;
  letter-spacing: .08em;
  text-shadow: 0 2px 8px #000;
  box-shadow: 0 8px 28px #0009;
  pointer-events: none;
}
.phase-announcement[hidden] { display: none; }

.game-result {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: block;
  background: #0b100dc9;
  color: #f3df8a;
  font: 800 clamp(32px, 7vw, 72px) "Yu Gothic UI", Meiryo, sans-serif;
  letter-spacing: .12em;
  text-shadow: 0 4px 18px #000;
  cursor: pointer;
}
.game-result[hidden] { display: none; }
.game-result::after {
  position: absolute;
  right: 0;
  bottom: clamp(22px, 6vh, 56px);
  left: 0;
  color: #fff4bd;
  content: "\300a Click to Next\300b";
  font: 700 clamp(16px, 2.4vw, 24px) Consolas, "Yu Gothic UI", Meiryo, sans-serif;
  letter-spacing: .04em;
  opacity: 0;
  text-align: center;
  transition: opacity 250ms ease;
}
.game-result.show-next::after { opacity: 1; animation: story-start-blink 1s steps(2, start) infinite; }
.game-result.fade-out { opacity: 0; transition: opacity 700ms ease; }
.game-result.show-game-over-options {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: clamp(18px, 4vh, 36px);
  padding: 24px;
}
.game-result.show-game-over-options::after { content: none; }
.game-result-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
}
.game-result.show-clear-rewards .game-result-message { inset: 0 0 22%; }
.game-result-rewards {
  position: absolute;
  right: 16px;
  bottom: clamp(72px, 15vh, 132px);
  left: 16px;
  display: grid;
  gap: 8px;
  color: #f4f1e8;
  font: 600 clamp(15px, 2.4vw, 23px)/1.4 "Yu Gothic UI", Meiryo, sans-serif;
  letter-spacing: .02em;
  text-align: center;
}
.game-result-rewards[hidden] { display: none; }
.game-result-rewards p { margin: 0; }
.game-result-rewards strong { color: #f1d978; }
.game-result.show-game-over-options .game-result-message {
  position: static;
  display: block;
  align-self: end;
}
.game-over-options {
  display: flex;
  width: min(100%, 340px);
  flex-direction: column;
  gap: 10px;
  align-self: start;
}
.game-over-options[hidden] { display: none; }
.game-over-options button {
  min-height: 48px;
  border: 1px solid #a89a61;
  border-radius: 5px;
  background: #172019ed;
  color: #fff4bd;
  font: 700 18px Consolas, "Yu Gothic UI", Meiryo, sans-serif;
  letter-spacing: .03em;
  cursor: pointer;
}
.game-over-options button.selected,
.game-over-options button:hover,
.game-over-options button:focus-visible {
  border-color: #fff1a1;
  background: #3b4530;
  outline: 2px solid #fff1a1;
  outline-offset: 2px;
}
.game-over-options button:disabled {
  border-color: #555b50;
  color: #898d83;
  cursor: default;
}
.game-over-options button:disabled:hover { outline: none; background: #172019ed; }

.turn-confirm {
  position: absolute;
  z-index: 4;
  top: 50%;
  left: 50%;
  min-width: 290px;
  padding: 20px;
  transform: translate(-50%, -50%);
  border: 1px solid #c4d0bd;
  border-radius: 6px;
  background: #1a241eeF;
  text-align: center;
  box-shadow: 0 10px 36px #000b;
}
.turn-confirm[hidden] { display: none; }
.turn-confirm p { margin: 0 0 16px; font-size: 16px; font-weight: 700; }
.turn-confirm div { display: flex; justify-content: center; gap: 10px; }
.turn-confirm button {
  padding: 7px 16px;
  border: 1px solid #637261;
  border-radius: 4px;
  background: #29392e;
  color: #e6eee8;
  font: 600 13px "Yu Gothic UI", Meiryo, sans-serif;
  cursor: pointer;
}
.turn-confirm button.selected, .turn-confirm button:hover { border-color: #f1d978; color: #f1d978; }
.status #phase-label { color: #d4e0d1; }

canvas {
  display: block;
  width: 100%;
  height: auto;
  outline: none;
  image-rendering: pixelated;
  touch-action: none;
  cursor: grab;
}
canvas:active { cursor: grabbing; }
canvas:focus-visible { box-shadow: inset 0 0 0 3px #e3cb75; }

.status {
  justify-content: flex-start;
  gap: 12px;
  padding: 14px 4px 0;
  color: #95a198;
  font: 11px Consolas, monospace;
  letter-spacing: .06em;
}
.status strong { color: #e9d783; font-weight: 500; }
.map-size { margin-left: auto; color: #78877d; }

@media (orientation: landscape) {
  .game-shell:not([hidden]) {
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr) clamp(112px, 30dvh, 170px) auto auto;
    gap: 6px;
    width: min(100% - 32px, 1080px);
    height: 100dvh;
    min-height: 0;
    padding: 8px 0;
  }
  .game-shell[hidden] { display: none; }
  .game-header { grid-row: 1; min-height: 0; margin: 0; }
  .game-header .eyebrow { display: none; }
  .game-header h1 { font-size: clamp(14px, 2.8vh, 20px); }
  .game-header .help { max-width: 42%; font-size: 10px; }
  .map-zoom-controls { grid-row: 2; min-height: 0; margin: 0; }
  .map-zoom-controls button { min-height: 28px; }
  .stage-preview-banner { grid-row: 3; }
  .map-frame {
    grid-row: 4;
    width: auto;
    max-width: 100%;
    height: 100%;
    min-height: 0;
    justify-self: center;
    margin: 0;
  }
  .battle-message-panel {
    grid-row: 5;
    width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
  }
  .battle-message-panel .story-window { padding-top: 4px; padding-bottom: 4px; }
  .battle-message-panel .story-portrait { height: min(110px, 26dvh); }
  .battle-message-panel .story-window .battle-message-content { padding-top: 4px; }
  .battle-message-panel .story-window .story-speaker:not(:empty) { margin-bottom: 4px; }
  .battle-message-panel .story-text { line-height: 1.45; }
  .touch-controls { grid-row: 6; }
  .status { grid-row: 7; min-height: 0; padding: 2px 4px 0; font-size: 10px; }
  .touch-controls:not([hidden]) { margin: 0; }
}

.touch-controls { display: none; }
.touch-controls[hidden] { display: none; }
.touch-controls button {
  width: 100%;
  min-height: 44px;
  border: 1px solid #657765;
  border-radius: 4px;
  background: #202b22;
  color: #f1d978;
  font: 600 15px "Yu Gothic UI", Meiryo, sans-serif;
  touch-action: manipulation;
}
.touch-controls button:active { background: #354536; }

@media (max-width: 600px) {
  .title-background { object-position: 38% center; }
  .title-shade { background: linear-gradient(90deg, transparent 0%, rgba(8, 12, 15, .25) 30%, rgba(8, 12, 15, .82) 100%); }
  .title-menu { right: 18px; width: 58vw; }
  .title-menu h1 { white-space: normal; font-size: clamp(24px, 7vw, 38px); }
  .title-options button { min-width: 100%; padding-left: 26px; font-size: clamp(14px, 4vw, 18px); }
  .game-shell { width: min(100% - 24px, 1080px); padding-top: 16px; }
  .help { max-width: 145px; text-align: right; line-height: 1.5; }
  .touch-controls:not([hidden]) { display: block; margin-top: 10px; }
  .game-result.show-game-over-options { gap: 8px; padding: 8px 12px; }
  .game-result.show-clear-rewards .game-result-message { inset: 0 0 50%; }
  .game-result.show-clear-rewards .game-result-rewards { bottom: 24%; }
  .game-over-options { gap: 6px; }
  .game-over-options button { min-height: 38px; font-size: 14px; }
  .map-scrollbar-x { right: 26px; height: 18px; }
  .map-scrollbar-y { right: -22px; bottom: 26px; width: 18px; }
}

.custom-screen {
  position: fixed;
  z-index: 28;
  inset: 0;
  display: grid;
  overflow: auto;
  place-items: center;
  padding: clamp(12px, 3vh, 28px) 16px;
  background: radial-gradient(ellipse at 50% 0, #39483a, #111714 72%);
  color: #172019;
}
.custom-screen[hidden] { display: none; }
.custom-panel { width: min(720px, 100%); }
.custom-header { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 14px; color: #f2e9d6; }
.custom-header h1 { font-size: clamp(20px, 4vw, 28px); }
.custom-points { display: flex; flex-wrap: wrap; justify-content: end; gap: 8px 18px; color: #d5dfd5; font-size: 13px; }
.custom-points strong { display: inline-block; min-width: 3em; margin-left: 6px; color: #f1d978; font-size: 17px; text-align: right; }
.custom-debug-panel { display: grid; grid-template-columns: 1fr auto; gap: 7px 14px; margin: 0 0 12px auto; padding: 10px 12px; width: min(360px, 100%); border: 1px solid #9aa58f; border-radius: 4px; background: #202a22; color: #f2e9d6; font-size: 13px; }
.custom-debug-panel[hidden] { display: none; }
.custom-debug-heading { display: flex; grid-column: 1 / -1; align-items: center; justify-content: space-between; gap: 10px; }
.custom-debug-heading label { display: flex; align-items: center; gap: 6px; }
.custom-debug-heading input { width: 76px; min-height: 30px; padding: 3px 6px; }
.custom-debug-resource { display: grid; grid-column: 1 / -1; grid-template-columns: 1fr 38px 38px; align-items: center; gap: 5px; }
.custom-debug-resource button { min-height: 30px; border: 1px solid #c4cdbb; background: #e4efdc; color: #172019; font: 700 16px "Yu Gothic UI", Meiryo, sans-serif; cursor: pointer; }
.custom-debug-panel > small { align-self: center; color: #c5cfbd; text-align: right; }
.custom-character-tabs { display: flex; align-items: end; gap: 4px; }
.custom-character-tabs button { position: relative; flex: 1 1 0; min-width: 0; height: 44px; padding: 0; overflow: hidden; border: 2px solid #161a17; border-bottom: 0; border-radius: 5px 5px 0 0; background: #969d96; color: #1b2520; font: 700 16px "Yu Gothic UI", Meiryo, sans-serif; cursor: pointer; transition: flex-grow 180ms ease, height 180ms ease, background-color 180ms ease; }
.custom-character-tabs button img { display: block; width: min(68px, 100%); height: 100%; margin: 0 auto; object-fit: cover; object-position: center 15%; image-rendering: pixelated; pointer-events: none; }
.custom-character-tabs button::after { position: absolute; inset: 0; background: rgb(0 0 0 / 50%); content: ""; pointer-events: none; }
.custom-character-tabs button[aria-selected="true"] { z-index: 1; flex-grow: 2; height: 72px; background: #e4efdc; }
.custom-character-tabs button[aria-selected="true"]::after { background: transparent; }
.custom-character-tabs button:focus-visible, .custom-row button:focus-visible, .custom-footer button:focus-visible { outline: 2px solid #f1d978; outline-offset: 2px; }
.custom-card { overflow: hidden; border: 3px solid #161a17; background: #e4efdc; }
.custom-row { display: grid; grid-template-columns: minmax(112px, 28%) 1fr 92px; min-height: 39px; border-bottom: 1px solid #687267; }
.custom-row:last-child { border-bottom: 0; }
.custom-label, .custom-value, .custom-equipment-value { display: flex; align-items: center; min-width: 0; padding: 5px 9px; border-right: 1px solid #687267; }
.custom-name-row strong { display: flex; align-items: center; padding: 5px 9px; font-weight: 600; }
.custom-name-row { background: #e4efdc; }
.custom-stat-row { background: #dce5f4; }
.custom-stat-row .custom-value { justify-content: center; }
.custom-row button { border: 0; border-left: 1px solid #687267; color: #172019; font: 700 17px "Yu Gothic UI", Meiryo, sans-serif; cursor: pointer; }
.custom-row button:disabled { opacity: .55; cursor: default; }
.custom-upgrade { background: #dce5f4; }
.custom-upgrade small { font-size: 11px; font-weight: 500; white-space: nowrap; }
.custom-upgrade:hover, .custom-select:hover { background: #f5e8b9; }
.custom-equipment-row { background: #f0f0f0; }
.custom-equipment-row .custom-label { white-space: nowrap; }
.custom-select { background: #f0f0f0; }
.custom-equipment-menu { display: flex; grid-column: 1 / -1; overflow-x: auto; border-top: 1px solid #687267; background: #fff8e6; }
.custom-equipment-menu[hidden] { display: none; }
.custom-weapon-card, .custom-equipment-card { flex: 0 0 190px; padding: 8px 12px; border: 0; border-right: 1px solid #687267; border-radius: 0; background: transparent; color: #172019; font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.custom-weapon-card:hover:not(:disabled), .custom-equipment-card:hover:not(:disabled) { background: #f5e8b9; }
.custom-weapon-card:disabled, .custom-equipment-card:disabled { opacity: .78; cursor: default; }
.custom-weapon-card:last-child, .custom-equipment-card:last-child { border-right: 0; }
.custom-weapon-name, .custom-equipment-name { display: block; min-height: 2.8em; margin-bottom: 5px; line-height: 1.4; }
.custom-weapon-stat, .custom-equipment-stat { white-space: nowrap; line-height: 1.65; }
.custom-weapon-price, .custom-equipment-price { margin-bottom: 5px; padding-bottom: 5px; border-bottom: 1px solid #c0c7bb; }
.custom-footer { display: flex; justify-content: flex-end; margin-top: 16px; }
.custom-footer button { min-width: 142px; min-height: 42px; border: 2px solid #171a17; background: #fff0c7; color: #1c211c; font: 600 15px "Yu Gothic UI", Meiryo, sans-serif; cursor: pointer; }
.custom-purchase-dialog { width: min(420px, calc(100% - 32px)); padding: 22px; border: 2px solid #161a17; background: #f5f0df; color: #172019; box-shadow: 0 8px 28px #0008; }
.custom-purchase-dialog::backdrop { background: #0009; }
.custom-purchase-dialog p { margin: 0 0 20px; white-space: pre-line; line-height: 1.7; }
.custom-purchase-actions { display: flex; justify-content: end; gap: 10px; }
.custom-purchase-actions button { min-width: 100px; min-height: 38px; border: 1px solid #4d5d4e; background: #e4efdc; color: #172019; font: 600 14px "Yu Gothic UI", Meiryo, sans-serif; cursor: pointer; }
.custom-purchase-actions button:hover { background: #f5e8b9; }
@media (max-width: 520px) {
  .custom-header { align-items: start; flex-direction: column; }
  .custom-points { justify-content: start; }
  .custom-row { grid-template-columns: minmax(92px, 29%) 1fr 83px; min-height: 36px; font-size: 13px; }
  .custom-upgrade small { font-size: 10px; }
}
