:root {
  color-scheme: dark;
  font-family: "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
  color: #f7f4ff;
  background: #17152c;
  --muted: #c4bbd6;
  --accent: #b8b6ff;
  --line: #4a4262;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 15% 8%, #30244f, transparent 60%);
}
.container { width: min(1160px, calc(100% - 48px)); margin-inline: auto; }
main { padding-block: 20px 44px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.preview {
  position: relative;
  justify-self: center;
  width: 100%;
  aspect-ratio: 16 / 10;
}
.preview-image {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: var(--image-width, 100%);
  aspect-ratio: var(--image-ratio, 16 / 10);
  overflow: hidden;
  background: #141222;
  border-radius: 14px;
}
.text-guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  fill: none;
  stroke: #54628b;
  stroke-opacity: .52;
  stroke-width: 1;
  stroke-dasharray: 4 3;
}
canvas { display: block; width: 100%; height: 100%; object-fit: contain; }
.editor { display: grid; gap: 12px; }
#answer, select {
  width: 100%;
  color: inherit;
  background: #191629;
  border: 1px solid var(--line);
  border-radius: 9px;
  margin: 0;
  padding: 10px 12px;
  font: inherit;
}
#answer {
  position: relative;
  min-height: 88px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #fff;
  color: #18151e;
  line-height: 1.3;
}
#answer[data-empty]::before {
  content: attr(aria-placeholder);
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 10px 12px;
  font-size: 18px;
  color: #716b7e;
  text-align: center;
  pointer-events: none;
}
.format-tools button, #color, #board-color {
  width: 36px;
  height: 36px;
  padding: 3px;
  margin: 0;
  color: inherit;
  background: #191629;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}
.format-tools button[aria-pressed="true"], .format-tools button[aria-pressed="mixed"] {
  color: var(--accent);
  border-color: var(--accent);
}
.format-tools button:hover { background: #38304e; }
#status { color: var(--muted); font-size: 12px; margin: 7px 0 0; }
#status:empty { display: none; }
button { font: 700 14px system-ui, sans-serif; }
#download {
  position: absolute;
  inset-block-start: 8px;
  inset-inline-end: 8px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 13px;
  color: #fff;
  background: #493477;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
}
#download:hover:not(:disabled) { background: #59418c; }
.download-icon {
  position: relative;
  width: 14px;
  height: 14px;
  border-bottom: 1.5px solid currentColor;
}
.download-icon::before, .download-icon::after {
  content: "";
  position: absolute;
  left: 50%;
}
.download-icon::before {
  top: 0;
  width: 1.5px;
  height: 9px;
  background: currentColor;
  transform: translateX(-50%);
}
.download-icon::after {
  top: 4px;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateX(-50%) rotate(45deg);
}
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (max-width: 760px) {
  .container { width: calc(100% - 32px); }
  .workspace { gap: 15px; }
  main.workspace { padding-block: 8px 16px; }
  .preview {
    /* 入力欄を先に表示し、短い回答と画像が一画面に収まるようにする。 */
    width: min(100%, max(220px, calc((100svh - 250px) * 1.6)));
  }
  #answer { min-height: 76px; }
}

.format-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #242039;
}
.tool-group { display: flex; align-items: center; gap: 4px; }
.tool-group + .tool-group { border-inline-start: 1px solid var(--line); padding-inline-start: 5px; }
@media (max-width: 850px) {
  .format-tools { flex-wrap: wrap; width: 100%; }
  .tool-group:first-child {
    flex: 0 0 100%;
    border-block-end: 1px solid var(--line);
    padding-bottom: 5px;
  }
  .tool-group:nth-child(2) {
    border-inline-start: 0;
    padding-inline-start: 0;
  }
  .tool-group:nth-child(3) { padding-inline-start: 2px; }
}
.format-tools select {
  height: 38px;
  margin: 0;
  padding: 4px;
  color: inherit;
  background: #191629;
  border: 1px solid var(--line);
  border-radius: 7px;
  font: inherit;
  font-size: 13px;
}
#font { width: 124px; }
.answer-line { display: block; min-height: 1.3em; }
.alignment-buttons { display: flex; gap: 2px; }
.alignment-icon {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 16px;
  margin: auto;
  border-block: 2px solid currentColor;
  padding-block: 3px;
}
.alignment-icon::before, .alignment-icon::after {
  content: "";
  width: 10px;
  height: 2px;
  background: currentColor;
}
[data-align="center"] .alignment-icon { align-items: center; }
[data-align="right"] .alignment-icon { align-items: flex-end; }
.format-tools button, .format-tools #color { width: 34px; height: 38px; }
.format-tools :disabled { opacity: .45; cursor: default; }
@media (max-width: 460px) {
  .tool-group { gap: 2px; }
  .format-tools button, .format-tools #color { width: clamp(22px, 7vw, 29px); }
}
.vertical-buttons { border-inline-start: 1px solid var(--line); padding-inline-start: 4px; }
.vertical-icon {
  position: relative;
  display: block;
  width: 16px;
  height: 16px;
  margin: auto;
}
.vertical-icon::before,
.vertical-icon::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: currentColor;
}
.vertical-icon::after {
  left: 3px;
  right: 3px;
  height: 6px;
  border-block: 2px solid currentColor;
  background: none;
}
[data-vertical="top"] .vertical-icon::before { top: 0; }
[data-vertical="top"] .vertical-icon::after { top: 4px; }
[data-vertical="middle"] .vertical-icon::before { top: 7px; }
[data-vertical="middle"] .vertical-icon::after { top: 2px; height: 12px; }
[data-vertical="bottom"] .vertical-icon::before { bottom: 0; }
[data-vertical="bottom"] .vertical-icon::after { bottom: 4px; }
@media (max-width: 350px) {
  .format-tools { gap: 2px; }
  .format-tools button, .format-tools #color { width: 21px; }
  .format-tools .alignment-buttons { gap: 1px; }
}

.font-size {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-inline: 4px;
  font-size: 12px;
  white-space: nowrap;
}
.font-size input {
  width: 160px;
  min-width: 40px;
  margin: 0;
  accent-color: var(--accent);
}
.font-size output {
  width: 3ch;
  text-align: end;
  font-variant-numeric: tabular-nums;
}
.format-tools #color {
  width: 42px;
  padding: 7px 9px;
  background: #332a4b;
  border-color: #746589;
}
.format-tools #color:not(:disabled):hover { background: #43355e; }
.format-tools #color:active:not(:disabled) { background: #51406c; }
#color::-webkit-color-swatch-wrapper { padding: 1px; }
#color::-webkit-color-swatch { border: 1px solid var(--muted); border-radius: 50%; }
#color::-moz-color-swatch { border: 1px solid var(--muted); border-radius: 50%; }
#board-color {
  flex: 0 0 38px;
  height: 38px;
  padding: 7px;
}
#board-color::-webkit-color-swatch-wrapper { padding: 0; }
#board-color::-webkit-color-swatch { border: 1px solid var(--muted); border-radius: 3px; }
#board-color::-moz-color-swatch { border: 1px solid var(--muted); border-radius: 3px; }
@media (max-width: 850px) {
  .font-size { flex: 1; min-width: 0; }
  .font-size input { flex: 1; width: 0; }
}

.scene-picker {
  display: flex;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 6px;
  mask-image: linear-gradient(to right, transparent, black var(--fade-start, 0px),
    black calc(100% - var(--fade-end, 0px)), transparent);
}
.scene-picker::-webkit-scrollbar { display: none; }
.scene-picker.can-scroll { cursor: grab; }
.scene-picker.is-dragging, .scene-picker.is-dragging button { cursor: grabbing; }
.scene-picker { user-select: none; }
.scene-picker button:first-child { margin-inline-start: auto; }
.scene-picker button:last-child { margin-inline-end: auto; }
.scene-picker button {
  flex: 0 0 76px;
  padding: 2px;
  border: 2px solid var(--line);
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
}
.scene-picker button[aria-pressed="true"] { border-color: var(--accent); }
.scene-picker img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  object-fit: contain;
  background: #fff;
  border-radius: 4px;
}
