:root {
  color-scheme: light dark;
  font-family: 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
  --bg: #f4f4f5;
  --ink: #111827;
  --accent: #3b82f6;
  --stroke: #111827;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 420px) 1fr;
  height: 100vh;
}

.input-pane {
  padding: 1.5rem;
  overflow-y: auto;
  background: #ffffffee;
  backdrop-filter: blur(6px);
  border-right: 1px solid rgba(17, 24, 39, 0.1);
}

.input-pane h1 {
  margin-top: 0;
  font-size: 1.3rem;
}

.input-pane p {
  font-size: 0.85rem;
  line-height: 1.6;
}

.input-label {
  display: block;
  margin-top: 1.1rem;
  margin-bottom: 0.35rem;
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.01em;
}

textarea {
  width: 100%;
  border: 1px solid rgba(17, 24, 39, 0.2);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.85rem;
  line-height: 1.5;
  resize: vertical;
  background-color: #fff;
}

input[type='password'],
input[type='text'] {
  width: 100%;
  border: 1px solid rgba(17, 24, 39, 0.2);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  background-color: #fff;
}

.small-print {
  font-size: 0.75rem;
  color: rgba(17, 24, 39, 0.55);
  margin-top: 0.25rem;
}

.actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

button {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background 0.2s ease;
}

button.button--ghost {
  background: rgba(59, 130, 246, 0.12);
  color: var(--accent);
}

button.button--ghost:hover {
  background: rgba(59, 130, 246, 0.22);
}

button:not(.button--ghost):hover {
  background: #2563eb;
}

.status {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: #2563eb;
}

.status[data-type='error'] {
  color: #dc2626;
}

.output-pane {
  padding: 1.25rem;
  overflow-y: auto;
}

.output-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: rgba(17, 24, 39, 0.75);
}

.toggle input {
  width: auto;
  accent-color: var(--accent);
}

.page-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding-bottom: 2rem;
}

.page-spread {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-direction: row-reverse;
}

.page-spread .page {
  flex: 1 1 50%;
}

.page {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.15);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 0.85rem;
  color: rgba(17, 24, 39, 0.7);
  gap: 0.75rem;
}

.page-header-right {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.page-meta {
  font-style: italic;
  color: rgba(17, 24, 39, 0.6);
}

.page-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.template-select {
  border: 1px solid rgba(17, 24, 39, 0.25);
  border-radius: 8px;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  background-color: #fff;
}

.page-canvas {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.page-canvas svg.storyboard {
  width: 100%;
  height: 100%;
  border: 1px solid rgba(17, 24, 39, 0.15);
  border-radius: 8px;
  background: #fff;
  display: block;
}

.page-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.page-overlay .overlay-item {
  position: absolute;
  box-sizing: border-box;
  font-family: 'Yu Gothic', sans-serif;
  color: rgba(17, 24, 39, 0.92);
  pointer-events: auto;
}

.panel-boundary {
  fill: none;
  stroke: var(--stroke);
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
}

.panel-label {
  font-size: 12px;
  fill: rgba(17, 24, 39, 0.6);
}

.panel-label.is-hidden {
  display: none;
}

.stage-callout {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  text-align: center;
  background: rgba(255, 255, 255, 0.88);
  border: 1px dashed rgba(17, 24, 39, 0.45);
  border-radius: 8px;
  padding: 0.4em 0.55em;
  line-height: 1.45;
  max-height: 100%;
  overflow: hidden;
  backdrop-filter: blur(2px);
  white-space: pre-wrap;
  word-break: break-word;
  writing-mode: horizontal-tb;
  align-items: center;
  pointer-events: none;
  z-index: 1;
}


.bubble-wrapper {
  position: absolute;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
  gap: 0.35rem;
  z-index: 2;
  cursor: grab;
}

.bubble-wrapper:active {
  cursor: grabbing;
}

.bubble {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: var(--bubble-padding-block, 1.5em) var(--bubble-padding-inline, 1.5em);
  box-sizing: border-box;
  background-color: #fff;
  border: 2px solid var(--stroke);
  writing-mode: vertical-rl;
  text-orientation: upright;
  line-height: 1.2;
  font-size: var(--bubble-font-size, 18px);
  font-weight: 700;
  color: var(--ink);
  height: auto !important;
  width: auto !important;
  min-width: auto !important;
}

.bubble::after {
  content: attr(data-speaker);
  position: absolute;
  display: none;
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: rgba(17, 24, 39, 0.75);
  pointer-events: none;
}

.bubble[data-speaker]::after {
  display: block;
}

.bubble[data-speaker-side='left']::after {
  left: 0;
  top: 50%;
  transform: translate(-115%, -50%);
}

.bubble[data-speaker-side='right']::after {
  right: 0;
  top: 50%;
  transform: translate(115%, -50%);
}

.bubble[data-speaker-side='center']::after {
  top: 0;
  left: 50%;
  transform: translate(-50%, -130%);
}

.bubble__text {
  white-space: pre-wrap;
  word-break: break-word;
  writing-mode: inherit;
  text-orientation: inherit;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.bubble--thought {
  border-style: dashed;
}

.bubble--dialogue,
.bubble--thought {
  border-radius: 50%;
}

.bubble--narration {
  border-width: 2px;
  justify-content: center;
}

.page-container[data-show-speakers='false'] .bubble::after {
  display: none !important;
}

.page-container[data-show-sfx='false'] .sfx-callout {
  display: none !important;
}

.sfx-callout {
  font-weight: 700;
  color: rgba(59, 130, 246, 0.95);
  text-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
  transform: translate(-50%, -50%);
  z-index: 3;
}

.stage-callout.is-hidden {
  display: none;
}

@media (max-width: 1100px) {
  .page-spread {
    flex-direction: column;
  }

  .page-spread .page {
    flex: 1 1 auto;
  }
}

.overlay-item.is-hidden {
  display: none;
}

