:root {
  --bg: #0d1b25;
  --panel: #f7fbff;
  --panel-2: #eef4fa;
  --border: #cbd6e2;
  --text: #172235;
  --text-dim: #5d6b7b;
  --accent: #1678c8;
  --ok: #1aa65d;
  --warn: #c9871f;
  --danger: #d61e1e;
  --blue-zone: rgba(22, 120, 200, 0.10);
  --red-zone: rgba(214, 30, 30, 0.08);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 0%, #29465a 0, #122838 34%, #09141d 100%);
  color: var(--text);
  font-weight: 600;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
}

.game-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  background: linear-gradient(180deg, rgba(25, 39, 49, .94), rgba(18, 30, 39, .97));
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 12px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.brand { display: flex; flex-direction: column; gap: 2px; min-width: 190px; }
.brand-title { margin: 0; font-size: 22px; color: #ffdf5a; font-weight: 900; text-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
.brand-sub { font-size: 13px; color: #fff; font-weight: 700; }
.brand-sub::before { content: "🐾 "; }

.head-progress-wrap { flex: 1; min-width: 160px; display: flex; flex-direction: column; gap: 4px; }
.head-progress-label { font-size: 11.5px; color: #dbe8f3; font-weight: 800; }
.head-progress { height: 14px; background: rgba(255, 255, 255, .18); border-radius: 999px; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0, 0, 0, .3); }
.head-progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #bfe3ff, var(--accent)); border-radius: 999px; transition: width .4s; }

/* ── Layout (cpu_quest/oop-gameと共通構造) ── */
.header-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.head-btn {
  height: 40px;
  padding: 0 16px;
  border: 2px solid rgba(255, 255, 255, .78);
  border-radius: 9px;
  background: rgba(0, 0, 0, .18);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .26);
  touch-action: manipulation;
}
.head-btn:hover { background: rgba(255, 255, 255, .15); }
a.head-btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.head-btn.home-badge {
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 223, 90, .45), rgba(15, 23, 31, 1) 75%);
  border: 2px solid #ffdf5a;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .25), 0 0 10px -2px #ffdf5a;
  font-size: 19px;
}
.head-btn.home-badge:hover {
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .25), 0 0 16px 0 #ffdf5a;
  transform: translateY(-2px) scale(1.07);
}

.game-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 14px;
  flex: 1;
  min-height: 0;
  transition: grid-template-columns .25s ease;
}

/* ── Side panel ── */
.side-panel {
  background: linear-gradient(180deg, rgba(39, 55, 64, .96), rgba(23, 38, 48, .98));
  position: sticky;
  top: 8px;
  align-self: start;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, .35);
  padding: 0;
  color: #fff;
  overflow: hidden;
  transition: width .25s ease;
}
.side-head {
  font-size: 14px;
  font-weight: 900;
  color: #dbe8f3;
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, .18);
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
}
.side-head-text { white-space: nowrap; }
.side-toggle {
  width: 36px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 7px;
  background: rgba(255, 255, 255, .10);
  color: #fff;
  font-weight: 950;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
}
.side-backdrop { display: none; }

/* Step list in sidebar */
.step-list { display: flex; flex-direction: column; }
.side-step {
  display: grid;
  grid-template-columns: 28px 1fr 20px;
  gap: 6px;
  align-items: center;
  min-height: 64px;
  padding: 8px 10px;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, .18);
  color: #cbd6de;
  position: relative;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  background: none;
  text-align: left;
  font-family: inherit;
  width: 100%;
}
.side-step:hover { background: rgba(255, 255, 255, .07); }
.side-step .paw { font-size: 18px; text-align: center; color: #9ba7ad; }
.side-step .side-step-label { font-size: 13px; font-weight: 950; line-height: 1.25; }
.side-step .status-icon { font-size: 16px; }
.side-step.active { background: rgba(9, 22, 31, .52); outline: 2px solid #d7b219; outline-offset: -3px; color: #fff; }
.side-step.done .paw { color: #ffd64c; }
.side-step.locked { opacity: 0.5; cursor: not-allowed; }

/* Collapsed sidebar */
.app-shell.side-collapsed .game-layout { grid-template-columns: 64px minmax(0, 1fr); }
.app-shell.side-collapsed .side-panel { width: 64px; }
.app-shell.side-collapsed .side-head { justify-content: center; padding: 8px 6px; }
.app-shell.side-collapsed .side-head-text { display: none; }
.app-shell.side-collapsed .step-list { flex-direction: column; }
.app-shell.side-collapsed .side-step { grid-template-columns: 1fr; justify-items: center; min-height: 48px; padding: 6px 4px; }
.app-shell.side-collapsed .side-step .side-step-label,
.app-shell.side-collapsed .side-step .status-icon { display: none; }

/* ── Desktop: サイドバーは常に展開 ── */
@media (min-width: 901px) {
  .app-shell.side-collapsed .game-layout { grid-template-columns: 230px minmax(0, 1fr) !important; }
  .app-shell.side-collapsed .side-panel { width: auto !important; }
  .app-shell.side-collapsed .side-head { justify-content: space-between !important; padding: 10px !important; }
  .app-shell.side-collapsed .side-head-text { display: block !important; }
  .app-shell.side-collapsed .side-step { grid-template-columns: 28px 1fr 20px !important; justify-items: start !important; min-height: 64px !important; padding: 8px 10px !important; }
  .app-shell.side-collapsed .side-step .side-step-label,
  .app-shell.side-collapsed .side-step .status-icon { display: block !important; }
}

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#dialogue-panel {
  padding: 12px 16px;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 #fff, var(--shadow);
}
#dialogue-panel:empty { display: none; }

#mission-banner {
  padding: 12px 18px;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 #fff, var(--shadow);
}

#mission-title { font-weight: 900; color: var(--accent); font-size: 16px; }
#mission-text { font-size: 13px; color: var(--text-dim); margin-top: 4px; white-space: pre-line; line-height: 1.7; font-weight: 700; }
#mission-status { font-size: 13px; margin-top: 6px; font-weight: 900; min-height: 18px; }
#mission-status.success { color: var(--ok); }
#mission-status.fail { color: var(--danger); }

#stage-area {
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 #fff, var(--shadow);
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#svg-wrap {
  position: relative;
  flex: 1;
  min-height: 360px;
  display: flex;
}

#network-svg {
  width: 100%;
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

#live-status {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: rgba(23, 34, 53, 0.88);
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
#live-status.show {
  opacity: 1;
  transform: translateY(0);
}
.live-line {
  padding: 1px 0;
  line-height: 1.5;
}
.live-line.err { color: #ff9d9d; }
.live-line.ok { color: #83edb3; }
.live-line.arp { color: #ffd97a; }

#stage-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 10px;
}

#stage-actions button {
  background: linear-gradient(#2ec66e, #1aa65d);
  color: #fff;
  border: 1px solid #0d7d37;
  box-shadow: 0 3px 0 #0a6930;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
  font-size: 13px;
}

#stage-actions button.secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 2px 0 var(--border);
}

#stage-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#stage-actions select, #stage-actions input[type=text] {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 700;
}

#stage-actions .quiz-row {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
  flex-wrap: wrap;
  background: #fff4df;
  border: 1px solid #e9b76d;
  border-radius: 8px;
  padding: 8px;
}

/* ── Responsive (cpu_quest/oop-gameと同一のブレークポイント/挙動) ── */
@media (max-width: 900px) {
  .app-shell { padding: 8px; gap: 8px; }
  .brand-title { font-size: 20px; }
  .game-layout { grid-template-columns: 64px minmax(0, 1fr); gap: 8px; }
  .app-shell:not(.side-collapsed) .game-layout { grid-template-columns: 210px minmax(0, 1fr); }
  .side-panel { display: block; order: 0; position: sticky; top: 8px; }
}
@media (max-width: 700px) {
  .game-layout { grid-template-columns: 1fr; }
  .app-shell.side-collapsed .game-layout,
  .app-shell:not(.side-collapsed) .game-layout { grid-template-columns: 1fr; }
  .side-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: min(82vw, 300px);
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 10px 0 30px rgba(0, 0, 0, .45);
    overflow-y: auto;
    z-index: 80;
  }
  .app-shell.side-collapsed .side-panel { transform: translateX(-100%); }
  .app-shell:not(.side-collapsed) .side-panel { transform: translateX(0); }
  .side-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(6, 12, 18, .55);
    z-index: 70;
  }
  .app-shell:not(.side-collapsed) .side-backdrop { display: block; }

  .game-header { padding: 8px 12px; }
  .brand-title { font-size: 18px; }
  .main-area { gap: 8px; }
  #dialogue-panel { padding: 8px 10px; }
  #mission-banner { padding: 8px 12px; }
  #svg-wrap { min-height: 260px; }
  #stage-actions button,
  #stage-actions select,
  #stage-actions input[type=text] {
    white-space: nowrap;
  }
  #control-bar { padding: 8px 12px; }
  #log-panel { padding: 8px 12px; height: 110px; }
  #live-status { left: 8px; right: 8px; bottom: 8px; font-size: 12px; padding: 7px 10px; }
}

#packet-detail-box, #table-views {
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 #fff, var(--shadow);
  padding: 10px 12px;
}

#packet-detail-box h3, #table-views h4 {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 900;
}

#packet-detail .hint { color: var(--text-dim); font-size: 12px; }

.detail-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 3px 0;
  border-bottom: 1px dashed var(--border);
}
.detail-row .k { color: var(--text-dim); }
.detail-row .v { font-family: "Consolas", monospace; font-weight: 700; }
.detail-row.highlight-same .v { color: var(--ok); }
.detail-row.highlight-change .v { color: var(--warn); }

.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-bottom: 10px;
}
.mini-table th, .mini-table td {
  border: 1px solid var(--border);
  padding: 3px 6px;
  text-align: left;
  font-family: "Consolas", monospace;
}
.mini-table th { color: var(--text-dim); background: var(--panel-2); font-weight: 900; }
.mini-table caption { text-align: left; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }

#control-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 #fff, var(--shadow);
  flex-wrap: wrap;
}

#control-bar button {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 2px 0 var(--border);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}
#control-bar button:hover { border-color: var(--accent); }
.speed-label { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; font-weight: 700; }

#log-panel {
  height: 140px;
  overflow-y: auto;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 #fff, var(--shadow);
  padding: 8px 18px;
}
#log-panel h3 { margin: 0 0 6px 0; font-size: 12px; color: var(--text-dim); font-weight: 900; }
#log-list { list-style: none; margin: 0; padding: 0; font-family: "Consolas", monospace; font-size: 12px; }
#log-list li { padding: 2px 0; border-bottom: 1px solid var(--panel-2); }
#log-list li.err { color: var(--danger); font-weight: 700; }
#log-list li.ok { color: var(--ok); font-weight: 700; }
#log-list li.arp { color: var(--warn); font-weight: 700; }

#book-recommend {
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 #fff, var(--shadow);
  padding: 10px 18px;
}
.book-recommend-label {
  display: inline-block;
  font-size: 10px;
  font-weight: 900;
  color: var(--text-dim);
  border: 1px solid var(--text-dim);
  border-radius: 4px;
  padding: 0 4px;
  margin: 0 0 6px;
}
.book-recommend-body { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.book-recommend-lead { font-size: 12px; color: var(--text-dim); margin: 0; font-weight: 700; }
#book-recommend a { font-size: 13px; color: var(--accent); font-weight: 900; text-decoration: underline; }

/* SVG elements */
.device-box {
  fill: var(--panel-2);
  stroke: var(--border);
  stroke-width: 1.5;
}
.device-box.pc { rx: 8; }
.device-label {
  fill: var(--text);
  font-size: 13px;
  font-weight: bold;
  text-anchor: middle;
  font-family: "Segoe UI", sans-serif;
}
.device-sub {
  fill: var(--text-dim);
  font-size: 10px;
  text-anchor: middle;
  font-family: "Consolas", monospace;
}
.device-icon {
  fill: none;
  stroke: var(--text);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.device-icon.filled {
  fill: var(--text);
  stroke: none;
}
.edge-line {
  stroke: var(--border);
  stroke-width: 3;
}
.edge-line.disconnected {
  stroke: var(--danger);
  stroke-dasharray: 6 6;
}
.edge-hit-area {
  stroke: transparent;
  stroke-width: 22;
  cursor: pointer;
}
.edge-break {
  fill: var(--danger);
  font-size: 16px;
  font-weight: bold;
  text-anchor: middle;
  pointer-events: none;
}

.subnet-zone {
  rx: 14;
  stroke: none;
}

.packet-hit-area {
  fill: transparent;
  cursor: pointer;
}
.packet-dot {
  cursor: pointer;
  stroke: #172235;
  stroke-width: 1.5;
  pointer-events: none;
}
.packet-dot.type-DATA { fill: #6b7a90; }
.packet-dot.type-ARP-REQUEST { fill: var(--warn); }
.packet-dot.type-ARP-REPLY { fill: var(--ok); }
.packet-dot.type-ICMP-ECHO { fill: var(--accent); }
.packet-dot.type-ICMP-REPLY { fill: #1fa6a0; }
.packet-dot.type-DHCP-DISCOVER { fill: var(--warn); }
.packet-dot.type-DHCP-OFFER { fill: #a35ff2; }
.packet-dot.type-DHCP-REQUEST { fill: #7d3fc9; }
.packet-dot.type-DHCP-ACK { fill: var(--ok); }
.packet-dot.type-DNS-QUERY { fill: #e0a90a; }
.packet-dot.type-DNS-RESPONSE { fill: var(--ok); }
.packet-dot.type-TCP-SYN { fill: #e6567b; }
.packet-dot.type-TCP-SYNACK { fill: #ca3868; }
.packet-dot.type-TCP-ACK { fill: var(--ok); }
.packet-dot.type-TCP-DATA { fill: var(--accent); }
.packet-dot.type-TCP-DATA-ACK { fill: #1fa6a0; }
.packet-dot.type-UDP-DATA { fill: #6b7a90; }
.packet-dot.type-HTTP-GET { fill: var(--accent); }
.packet-dot.type-HTTP-RESPONSE { fill: #1fa6a0; }
.packet-dot.type-TLS-CLIENTHELLO { fill: #e0a90a; }
.packet-dot.type-TLS-SERVERHELLO { fill: #a35ff2; }
.packet-dot.type-TLS-KEYEXCHANGE { fill: #e6567b; }
.packet-dot.type-TLS-FINISHED { fill: var(--ok); }
.packet-dot.type-TLS-APPDATA { fill: #1fa6a0; }
.packet-dot.selected { stroke: #ffd44a; stroke-width: 3; }

.packet-label {
  font-size: 9px;
  fill: var(--text-dim);
  text-anchor: middle;
  pointer-events: none;
}

/* ===== ねこ先生とうさ美の会話システム（oop-gameより） ===== */
.dialog-scene {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dialog-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  border: 1px solid #cbd6e2;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: inset 0 1px 0 #fff, 0 2px 0 rgba(20, 45, 70, .04);
}
.dialog-row.right {
  grid-template-columns: minmax(0, 1fr) 110px;
}
.dialog-row.right .dialog-character { order: 2; }
.dialog-row.right .dialog-bubble { order: 1; }
.dialog-character {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  align-self: center;
  min-width: 0;
}
.dialog-character img {
  width: 92px;
  max-width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .12));
}
.dialog-name {
  margin-top: -2px;
  padding: 3px 10px;
  border-radius: 7px;
  color: #fff;
  font-weight: 900;
  font-size: 12px;
  line-height: 1.2;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .16);
  white-space: nowrap;
}
.dialog-name.cat { background: linear-gradient(#4e9548, #2d7332); }
.dialog-name.rabbit { background: linear-gradient(#e78091, #ca5368); }
.dialog-bubble {
  position: relative;
  align-self: center;
  background: #fff;
  border: 1px solid #cbd6e2;
  border-radius: 12px;
  padding: 11px 14px;
  color: #172235;
  font-size: 14px;
  line-height: 1.8;
  font-weight: 700;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.dialog-bubble::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 0; height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 10px solid #cbd6e2;
}
.dialog-bubble::after {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 0; height: 0;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-right: 9px solid #fff;
}
.dialog-row.right .dialog-bubble::before {
  left: auto; right: -10px;
  border-right: 0;
  border-left: 10px solid #cbd6e2;
}
.dialog-row.right .dialog-bubble::after {
  left: auto; right: -8px;
  border-right: 0;
  border-left: 9px solid #fff;
}
.dialog-bubble strong { color: #d61e1e; font-weight: 950; }

@media (max-width: 700px) {
  .dialog-row, .dialog-row.right { grid-template-columns: 74px minmax(0, 1fr); padding: 8px; gap: 8px; }
  .dialog-row.right .dialog-character { order: 0; }
  .dialog-row.right .dialog-bubble { order: 1; }
  .dialog-character img { width: 66px; }
  .dialog-name { font-size: 10px; padding: 3px 7px; }
  .dialog-bubble { font-size: 13px; padding: 9px 11px; min-height: 0; }
  .dialog-row.right .dialog-bubble::before { left: -10px; right: auto; border-left: 0; border-right: 10px solid #cbd6e2; }
  .dialog-row.right .dialog-bubble::after { left: -8px; right: auto; border-left: 0; border-right: 9px solid #fff; }
}
