:root {
  color-scheme: light;
  --ink: #172127;
  --muted: #66757d;
  --line: #dce4e7;
  --paper: #ffffff;
  --background: #f4f7f6;
  --primary: #087b69;
  --primary-dark: #056151;
  --accent: #ffb454;
  --danger: #b83b45;
  font-family: Inter, "Noto Sans JP", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--background); }
button, input, select, textarea { font: inherit; }
button { border: 0; border-radius: 8px; padding: 10px 15px; color: #fff; background: var(--primary); cursor: pointer; font-weight: 700; }
button:hover { background: var(--primary-dark); }
button.secondary { color: var(--primary); background: #e5f2ef; }
button.danger { color: var(--danger); background: #fae9eb; }
button:disabled { cursor: not-allowed; opacity: .5; }

.app-header { display: flex; justify-content: space-between; gap: 30px; padding: 24px clamp(20px, 5vw, 72px); color: #fff; background: linear-gradient(120deg, #093d3a, #087b69); }
.app-header h1 { margin: 2px 0 7px; font-size: clamp(25px, 3vw, 38px); }
.app-header p { margin: 0; opacity: .88; }
.eyebrow { font-size: 11px; font-weight: 800; letter-spacing: .18em; }
.connection-panel { display: flex; align-items: end; gap: 8px; min-width: min(100%, 380px); }
.connection-panel label { flex: 1; font-size: 12px; }
.connection-panel input { margin-top: 6px; }

.scenario-nav { position: sticky; top: 0; z-index: 900; display: flex; align-items: center; gap: 8px; padding: 12px clamp(20px, 5vw, 72px); border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); backdrop-filter: blur(8px); }
.scenario-nav select { min-width: 260px; }
#statusMessage { margin-left: auto; color: var(--muted); font-size: 13px; }
#statusMessage.error { color: var(--danger); font-weight: 700; }
#statusMessage.success { color: var(--primary); font-weight: 700; }

main { display: grid; gap: 18px; width: min(1500px, calc(100% - 32px)); margin: 22px auto 60px; }
.card { border: 1px solid var(--line); border-radius: 14px; padding: 20px; background: var(--paper); box-shadow: 0 4px 18px rgba(20, 52, 55, .05); }
.section-title, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 16px; }
.section-title > div:first-child { display: flex; align-items: center; gap: 10px; }
.section-title span { display: grid; place-items: center; width: 31px; height: 31px; border-radius: 50%; color: var(--primary); background: #dff2ed; font-size: 12px; font-weight: 900; }
h2, h3 { margin: 0; }
.section-title small { color: var(--muted); }

.form-grid { display: grid; gap: 12px; }
.form-grid.three { grid-template-columns: 1fr 1.3fr 2fr; }
.form-grid.four { grid-template-columns: repeat(4, 1fr); }
label { display: grid; gap: 6px; color: #4e5c63; font-size: 12px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #c8d3d7; border-radius: 7px; padding: 9px 10px; color: var(--ink); background: #fff; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(8,123,105,.14); border-color: var(--primary); }

.map-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(360px, 1fr); gap: 18px; }
#map { height: 560px; border: 1px solid var(--line); border-radius: 10px; background: #e6eceb; }
.map-help { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.zone-panel { max-height: 666px; overflow: auto; }
.panel-heading strong { color: var(--primary); }
.stack-list, .event-list { display: grid; gap: 12px; }
.zone-row, .event-row { border: 1px solid var(--line); border-radius: 10px; padding: 13px; background: #fbfcfc; }
.zone-row.active { border-color: var(--primary); box-shadow: inset 3px 0 var(--primary); }
.row-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.row-header strong { font-size: 14px; }
.mini-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.coordinates { grid-template-columns: 1fr 1fr .7fr; }
.empty-message { padding: 26px 10px; color: var(--muted); text-align: center; }

.event-row { display: grid; grid-template-columns: minmax(170px, .9fr) minmax(220px, 1fr) minmax(290px, 1.4fr) minmax(190px, .8fr); gap: 14px; }
.event-block { display: grid; align-content: start; gap: 8px; }
.event-block h4 { margin: 0 0 4px; color: var(--primary); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.action-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
.action-options label { display: flex; align-items: center; gap: 5px; padding: 5px; border-radius: 5px; background: #edf4f2; font-size: 11px; }
.action-options input { width: auto; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
#jsonPreview { min-height: 280px; max-height: 600px; overflow: auto; border-radius: 9px; padding: 16px; color: #d9f5ed; background: #102a2a; font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; }

@media (max-width: 1050px) {
  .map-layout { grid-template-columns: 1fr; }
  .zone-panel { max-height: none; }
  .event-row { grid-template-columns: repeat(2, 1fr); }
  .form-grid.three, .form-grid.four { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 680px) {
  .app-header, .scenario-nav, .section-title { align-items: stretch; flex-direction: column; }
  .connection-panel, .button-row { flex-direction: column; }
  .scenario-nav select { min-width: 0; }
  #statusMessage { margin-left: 0; }
  .event-row, .form-grid.three, .form-grid.four, .mini-grid, .coordinates { grid-template-columns: 1fr; }
  #map { height: 430px; }
}
