:root {
  color-scheme: dark;
  --bg: #071018;
  --panel: #0d1b25;
  --panel-soft: #112432;
  --line: #274455;
  --text: #e9f4f5;
  --muted: #91afb5;
  --cyan: #74e4dc;
  --cyan-soft: rgba(116, 228, 220, .14);
  --red: #ff6d78;
  --red-soft: rgba(255, 109, 120, .2);
  --amber: #f5c56a;
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 15% 0%, rgba(38, 112, 126, .18), transparent 34rem),
    linear-gradient(180deg, #071018 0%, #0a141d 100%);
  color: var(--text);
  font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  line-height: 1.65;
}

button, textarea { font: inherit; }
a { color: inherit; }
.page-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; padding: 22px 0 34px; border-bottom: 1px solid rgba(145, 175, 181, .18);
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--cyan); border-radius: 9px; color: var(--cyan); font-weight: 800; }
.brand strong, .brand small { display: block; line-height: 1.2; }
.brand small { margin-top: 4px; color: var(--muted); font-size: .72rem; letter-spacing: .12em; }
nav { display: flex; gap: 16px; color: var(--muted); font-size: .86rem; }
nav a { text-decoration: none; }
nav a:hover, nav a:focus-visible { color: var(--cyan); }

main { padding: 54px 0 72px; }
.intro { max-width: 850px; margin-bottom: 32px; }
.eyebrow, .section-label { color: var(--cyan); font-size: .72rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { max-width: 100%; margin-bottom: 8px; font-size: clamp(2.2rem, 7vw, 4.2rem); line-height: 1.08; letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: clamp(1.2rem, 2.4vw, 1.8rem); line-height: 1.2; }
.lead { margin-bottom: 12px; color: #c4d9dc; font-size: clamp(1.05rem, 2vw, 1.35rem); }
.device-note { display: inline-block; margin-bottom: 0; padding: 5px 10px; border: 1px solid rgba(245, 197, 106, .45); border-radius: 999px; color: var(--amber); font-size: .82rem; }

.game-panel, .result-panel { padding: clamp(18px, 3vw, 34px); border: 1px solid var(--line); border-radius: 22px; background: linear-gradient(135deg, rgba(17, 36, 50, .96), rgba(8, 19, 28, .98)); box-shadow: 0 24px 70px rgba(0, 0, 0, .22); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(86px, 1fr)); gap: 8px; min-width: min(100%, 340px); }
.stats div { padding: 8px 10px; border: 1px solid rgba(145, 175, 181, .18); border-radius: 12px; background: rgba(0, 0, 0, .14); }
.stats span, .stats small { display: block; color: var(--muted); font-size: .7rem; }
.stats strong { display: inline-block; margin-right: 3px; font-size: 1.15rem; color: var(--text); }
.status-line { min-height: 2.1em; margin: 28px 0 16px; padding: 10px 14px; border-left: 3px solid var(--cyan); background: var(--cyan-soft); color: #d7eeee; }
.status-line.is-alert { border-color: var(--red); background: var(--red-soft); }
.status-line.is-success { border-color: var(--cyan); }
.document-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.original-card, .editor-card { min-width: 0; overflow: hidden; border: 1px solid rgba(145, 175, 181, .22); border-radius: 14px; background: rgba(2, 9, 14, .52); }
.label-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 13px; border-bottom: 1px solid rgba(145, 175, 181, .16); color: var(--muted); font-size: .74rem; }
.document-text { width: 100%; min-height: 184px; margin: 0; padding: 17px; border: 0; font-family: "Cascadia Mono", "Yu Gothic UI", Meiryo, monospace; font-size: clamp(.95rem, 1.5vw, 1.05rem); line-height: 1.9; letter-spacing: .02em; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.source-text { user-select: none; cursor: default; color: #c2d8dc; }
.editor-wrap { position: relative; min-height: 184px; overflow: auto; }
.editor, .damage-overlay { min-height: 184px; padding: 17px; }
.editor { position: relative; z-index: 1; display: block; resize: none; outline: none; overflow: auto; background: transparent; color: var(--text); caret-color: var(--cyan); }
.editor:disabled { opacity: .82; cursor: not-allowed; }
.editor:not(:disabled):focus { box-shadow: inset 0 0 0 2px rgba(116, 228, 220, .34); }
.damage-overlay { position: absolute; z-index: 2; inset: 0; height: 100%; overflow: hidden; pointer-events: none; color: transparent; }
.damage { color: transparent; background: var(--red-soft); border-bottom: 2px solid var(--red); }
.damage.residue { background: rgba(245, 197, 106, .14); border-bottom-color: var(--amber); }
.intruder-caret { display: inline-block; width: 0; height: 1.25em; margin-right: 1px; border-left: 2px solid var(--red); vertical-align: -.18em; }
.deletion-marker { display: inline-block; width: 0; height: 1.15em; margin-right: 1px; border-left: 2px dashed var(--red); vertical-align: -.12em; }
.event-strip { display: flex; align-items: baseline; gap: 14px; min-height: 31px; margin-top: 14px; color: var(--muted); font-size: .83rem; }
.action-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 43px; padding: 9px 18px; border: 1px solid var(--line); border-radius: 10px; background: rgba(116, 228, 220, .06); color: var(--text); cursor: pointer; font-weight: 700; }
.button:hover, .button:focus-visible { border-color: var(--cyan); background: var(--cyan-soft); }
.button.primary { border-color: var(--cyan); background: var(--cyan); color: #061115; }
.button.primary:hover, .button.primary:focus-visible { background: #9af3ec; }
.button:disabled { opacity: .5; cursor: not-allowed; }
.help-text { margin: 14px 0 0; color: var(--muted); font-size: .82rem; }

.result-panel { margin-top: 20px; border-color: rgba(116, 228, 220, .34); }
.result-main { display: flex; align-items: baseline; gap: 8px; margin: 18px 0 22px; color: var(--muted); }
.result-main strong { color: var(--cyan); font-size: clamp(2.4rem, 7vw, 4.7rem); line-height: 1; }
.result-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 0; }
.result-grid div { padding: 12px; border: 1px solid rgba(145, 175, 181, .18); border-radius: 12px; }
.result-grid dt { color: var(--muted); font-size: .72rem; }
.result-grid dd { margin: 4px 0 0; font-size: 1.1rem; font-weight: 800; }
.result-note { margin: 18px 0 0; color: var(--muted); }
.site-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; padding: 18px 0 30px; border-top: 1px solid rgba(145, 175, 181, .16); color: var(--muted); font-size: .78rem; }
.site-footer a { color: var(--cyan); text-decoration: none; }

@media (max-width: 780px) {
  .page-shell { width: min(100% - 22px, 620px); }
  .site-header { align-items: flex-start; padding-bottom: 24px; }
  nav { gap: 10px; font-size: .78rem; }
  main { padding-top: 36px; }
  .panel-heading { display: block; }
  .stats { min-width: 0; margin-top: 18px; }
  .document-grid { grid-template-columns: 1fr; }
  .document-text { min-height: 160px; }
  .editor-wrap, .editor, .damage-overlay { min-height: 160px; }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 430px) {
  .page-shell { width: min(100% - 16px, 390px); }
  h1 { font-size: 2.35rem; }
  .game-panel, .result-panel { padding: 16px; border-radius: 16px; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
  .stats div { padding: 7px 5px; }
  .stats strong { font-size: .95rem; }
  .document-text { padding: 13px; font-size: .88rem; line-height: 1.8; }
  .editor, .damage-overlay { padding: 13px; }
}
