:root {
  --bg: #0a1222;
  --surface: #111a2f;
  --surface-soft: #16213a;
  --surface-ink: #0d1528;
  --text: #ecf1ff;
  --muted: #9cabcd;
  --accent: #29d5a5;
  --line-soft: rgba(121, 145, 193, 0.2);
  --shadow: 0 14px 34px rgba(5, 9, 20, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  background:
    radial-gradient(circle at 85% -10%, #23498d 0%, transparent 42%),
    radial-gradient(circle at 10% 110%, #174d5d 0%, transparent 38%),
    var(--bg);
  font-family: "IBM Plex Sans", "Noto Sans JP", sans-serif;
}

select,
input,
textarea,
button {
  font: inherit;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
  padding: 0;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 68px;
  width: 100%;
  padding: 10px 18px;
  background: linear-gradient(90deg, #10203c, #1a3562);
  border-radius: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 0;
  background: transparent;
  padding: 0;
  flex: 0 0 44px;
}

.logo.is-hidden {
  display: none;
}

.brand-copy h1 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.2;
}

.selection-bar {
  display: flex;
  align-items: end;
  gap: 12px;
  margin: 0 14px;
  padding: 10px 0 0;
}

.selectors {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.fixed-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--muted);
}

.rule-field {
  width: 190px;
  flex: 0 0 190px;
}

.stage-field {
  width: 320px;
  flex: 0 0 320px;
}

select,
input[type="text"],
textarea {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  padding: 9px 10px;
}

.selection-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.selection-actions button {
  width: 40px;
  height: 40px;
}

.workspace {
  min-height: 0;
  height: clamp(560px, 74vh, 860px);
  display: grid;
  grid-template-columns: minmax(0, 1.42fr) minmax(300px, 0.58fr);
  gap: 0;
  margin: 0 14px;
  background: linear-gradient(180deg, rgba(21, 33, 59, 0.92), rgba(15, 24, 43, 0.92));
  border-radius: 6px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.left-pane {
  padding: 12px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.right-pane {
  min-height: 0;
  border-left: 1px solid var(--line-soft);
  padding: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.map-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 0;
  background: var(--surface-ink);
  border-radius: 6px;
  overflow: hidden;
}

#mapImage,
#drawLayer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#mapImage {
  object-fit: contain;
  background: #0a111f;
}

#drawLayer {
  touch-action: none;
  cursor: crosshair;
}

.text-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: auto;
}

.text-layer.disabled {
  pointer-events: none;
}

.map-text-item {
  position: absolute;
  min-width: 120px;
  max-width: 48%;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  padding: 3px 5px;
  line-height: 1.35;
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
  outline: none;
}

.map-text-item.editing {
  border-color: rgba(154, 176, 216, 0.55);
}

.map-text-item.committed {
  border-color: transparent;
}

.map-text-item.hand-mode {
  cursor: grab;
}

.map-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 6px;
  text-align: center;
  background: rgba(8, 14, 30, 0.72);
  color: var(--muted);
}

.map-placeholder p {
  margin: 0;
  color: #d7e0f8;
  font-weight: 600;
}

.map-placeholder[hidden] {
  display: none;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px;
  border-radius: 6px;
  background: rgba(11, 19, 36, 0.86);
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-group button {
  width: 40px;
  height: 40px;
  padding: 0;
}

.tool-group button.active {
  background: #2b72d1;
}

.tool-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.icon-btn {
  border: 0;
  border-radius: 5px;
  color: var(--text);
  background: var(--surface-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: #253350;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.header-icon-btn {
  width: 38px;
  height: 38px;
  background: rgba(255, 255, 255, 0.14);
}

.header-icon-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

#widthInput {
  width: 112px;
}

.notes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.notes-header h2 {
  margin: 0;
  font-size: 1rem;
}

.notes-header button {
  width: 140px;
  height: 36px;
  border: 0;
  border-radius: 5px;
  color: #09261b;
  font-weight: 700;
  background: var(--accent);
  cursor: pointer;
  white-space: nowrap;
}

.note-list {
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.note-card {
  border-radius: 6px;
  background: rgba(9, 16, 31, 0.75);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: grab;
}

.note-card.dragging {
  opacity: 0.48;
}

.note-card.drag-over-before {
  box-shadow: inset 0 2px 0 #9eb0d8;
}

.note-card.drag-over-after {
  box-shadow: inset 0 -2px 0 #9eb0d8;
}

.note-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.note-title-input {
  flex: 1 1 auto;
  height: 40px;
}

.note-delete {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 5px;
  background: var(--surface-soft);
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.note-delete:hover {
  background: #253350;
  color: var(--text);
}

.note-delete svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.note-body-input {
  min-height: 72px;
  resize: none;
  overflow: hidden;
}

.note-card input,
.note-card textarea {
  cursor: text;
}

.status-bar {
  min-height: 24px;
  margin: 0 14px 8px;
  padding: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 30;
}

.confirm-modal[hidden] {
  display: none;
}

.confirm-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 14, 0.55);
}

.confirm-dialog {
  position: relative;
  width: min(420px, calc(100vw - 32px));
  background: #131d34;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.confirm-dialog h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.confirm-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.confirm-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.confirm-actions button {
  min-width: 92px;
  height: 36px;
  border: 0;
  border-radius: 5px;
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
}

#confirmDeleteBtn {
  background: #2a3c5f;
}

.settings-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 28;
}

.settings-modal[hidden] {
  display: none;
}

.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 14, 0.45);
}

.settings-dialog {
  position: relative;
  width: min(420px, calc(100vw - 32px));
  background: #131d34;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.settings-dialog h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.settings-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.settings-actions button {
  min-width: 92px;
  height: 36px;
  border: 0;
  border-radius: 5px;
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
}

@media (max-width: 1220px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    margin: 0 10px;
  }

  .right-pane {
    border-left: 0;
    border-top: 1px solid var(--line-soft);
  }

  .map-frame {
    min-height: 430px;
    aspect-ratio: auto;
  }

  .selection-bar {
    align-items: start;
    flex-direction: column;
    gap: 10px;
    margin: 0 10px;
    padding: 6px 0 0;
  }

  .selection-actions {
    margin-left: 0;
  }

  .status-bar {
    margin: 0 10px 8px;
  }
}

@media (max-width: 760px) {
  .banner {
    flex-wrap: wrap;
    min-height: auto;
  }

  .rule-field,
  .stage-field {
    width: 100%;
    flex: 1 1 100%;
  }

  .tool-group button {
    width: 36px;
    height: 36px;
  }
}
