:root {
  color-scheme: light;
  --paper: #fbfaf6;
  --grid: rgba(20, 20, 18, 0.055);
  --grid-strong: rgba(20, 20, 18, 0.12);
  --ink: #161513;
  --muted: #6e6a60;
  --line: rgba(20, 20, 18, 0.14);
  --panel: rgba(255, 255, 255, 0.92);
  --blue: #2f6df6;
  --red: #d84c45;
  --shadow: 0 18px 48px rgba(31, 28, 22, 0.14);
  --grid-size: 48px;
  --grid-big: 240px;
  --grid-x: 0px;
  --grid-y: 0px;
  --ui-scale: 1;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app,
.whiteboard {
  position: relative;
  width: 100vw;
  height: 100dvh;
}

.whiteboard {
  overflow: hidden;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(var(--grid-strong) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-strong) 1px, transparent 1px),
    radial-gradient(circle at 20% 10%, rgba(47, 109, 246, 0.07), transparent 34rem),
    var(--paper);
  background-size:
    var(--grid-size) var(--grid-size),
    var(--grid-size) var(--grid-size),
    var(--grid-big) var(--grid-big),
    var(--grid-big) var(--grid-big),
    auto,
    auto;
  background-position:
    var(--grid-x) var(--grid-y),
    var(--grid-x) var(--grid-y),
    var(--grid-x) var(--grid-y),
    var(--grid-x) var(--grid-y),
    center,
    center;
}

.world,
.panels-layer {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

.empty-state {
  position: absolute;
  left: 50%;
  top: 50%;
  max-width: min(420px, calc(100vw - 32px));
  margin: 0;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  text-align: center;
  box-shadow: var(--shadow);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.comic-panel {
  position: absolute;
  overflow: hidden;
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: 0 18px 30px rgba(20, 20, 18, 0.1);
}

.comic-panel.is-selected {
  outline: calc(2px * var(--ui-scale)) solid var(--blue);
  outline-offset: calc(5px * var(--ui-scale));
}

.panel-canvas {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 48%, rgba(0, 0, 0, 0.03), transparent 34%),
    #fff;
}

.panel-element {
  position: absolute;
  z-index: 2;
  transform-origin: center center;
  cursor: grab;
  touch-action: none;
}

.panel-element:active {
  cursor: grabbing;
}

.panel-element.is-element-selected {
  outline: calc(2px * var(--ui-scale)) dashed rgba(47, 109, 246, 0.78);
  outline-offset: calc(5px * var(--ui-scale));
}

.element-resize-handle,
.element-rotate-handle {
  position: absolute;
  z-index: 10;
  width: calc(24px * var(--ui-scale));
  height: calc(24px * var(--ui-scale));
  border: calc(3px * var(--ui-scale)) solid var(--blue);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.element-resize-handle {
  right: calc(-13px * var(--ui-scale));
  bottom: calc(-13px * var(--ui-scale));
  cursor: nwse-resize;
}

.element-rotate-handle {
  left: 50%;
  top: calc(-38px * var(--ui-scale));
  transform: translateX(-50%);
  cursor: grab;
}

.element-rotate-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: calc(2px * var(--ui-scale));
  height: calc(14px * var(--ui-scale));
  background: var(--blue);
}

.template-art {
  color: #050505;
}

.template-art.close {
  width: 90%;
  height: 90%;
}

.template-art.bust {
  height: 84%;
}

.person-head,
.person-body,
.person-shoulder,
.person-neck,
.person-arm,
.person-leg {
  position: absolute;
  left: 50%;
}

.person-head {
  top: 7%;
  width: 26%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: currentColor;
  transform: translateX(-50%);
}

.person-face {
  display: none;
}

.person-neck {
  top: 32%;
  width: 13%;
  height: 8%;
  border-radius: 999px;
  background: currentColor;
  transform: translateX(-50%);
}

.template-art.close .person-head {
  top: 12%;
  width: 56%;
}

.person-body {
  top: 39%;
  width: 24%;
  height: 48%;
  border-radius: 999px;
  background: currentColor;
  transform: translateX(-50%);
}

.person-body::after {
  display: none;
}

.template-art.bust .person-body {
  top: 42%;
  width: 30%;
  height: 33%;
  border-radius: 999px;
}

.template-art.close .person-body {
  top: 74%;
  width: 34%;
  height: 16%;
}

.person-arm {
  display: none;
  top: 56%;
  width: 9%;
  height: 28%;
  border-radius: 999px;
  background: currentColor;
  transform-origin: top center;
  opacity: 0.88;
}

.person-arm.left {
  left: 36%;
  transform: rotate(12deg);
}

.person-arm.right {
  left: 64%;
  transform: rotate(-12deg);
}

.person-leg {
  display: none;
  top: 82%;
  width: 9%;
  height: 11%;
  border-radius: 999px;
  background: currentColor;
  transform-origin: top center;
  opacity: 0.9;
}

.person-leg.left {
  left: 44%;
  transform: rotate(2deg);
}

.person-leg.right {
  left: 56%;
  transform: rotate(-2deg);
}

.person-shoulder {
  display: none;
}

.template-art.close .person-shoulder,
.template-art.close .person-arm,
.template-art.close .person-leg {
  display: none;
}

.template-art.bust .person-arm {
  top: 58%;
  height: 20%;
}

.template-art.bust .person-leg {
  display: none;
}

.image-prop {
  background: center / contain no-repeat;
}

.character-label {
  position: absolute;
  left: 50%;
  top: -10px;
  z-index: 11;
  max-width: 150px;
  padding: 4px 9px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.05);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  pointer-events: none;
}

.bubble-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.speech-bubble {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 60px;
  min-height: 118px;
  max-width: 42%;
  max-height: 62%;
  padding: 18px 13px;
  border: 3.5px solid var(--ink);
  background: #fff;
  color: var(--ink);
  box-shadow: 0 9px 0 rgba(0, 0, 0, 0.035);
  line-height: 1.45;
  letter-spacing: 0.03em;
  text-align: center;
  text-orientation: mixed;
  white-space: pre-wrap;
  writing-mode: vertical-rl;
  transform-origin: top center;
  pointer-events: auto;
}

.speech-bubble.round {
  border-radius: 58% 48% 54% 46% / 48% 56% 44% 52%;
}

.speech-bubble.thought {
  border-radius: 48% 56% 45% 54% / 52% 45% 55% 48%;
}

.speech-bubble.narration {
  min-height: 96px;
  border-radius: 0;
  box-shadow: 7px 7px 0 rgba(0, 0, 0, 0.08);
}

.speech-bubble::after {
  content: "";
  position: absolute;
  left: 16%;
  bottom: -18px;
  width: 30px;
  height: 28px;
  border-bottom: 3.5px solid var(--ink);
  border-left: 3.5px solid var(--ink);
  background: #fff;
  transform: rotate(-32deg) skew(-20deg);
  transform-origin: center;
}

.speech-bubble.thought::after {
  left: 21%;
  bottom: -21px;
  width: 13px;
  height: 13px;
  border: 3.5px solid var(--ink);
  border-radius: 50%;
  background: #fff;
  transform: none;
  box-shadow:
    16px 10px 0 -2px #fff,
    16px 10px 0 1.5px var(--ink),
    31px 18px 0 -4px #fff,
    31px 18px 0 -1px var(--ink);
}

.speech-bubble.narration::after {
  display: none;
}

.bubble-text {
  display: block;
  min-width: 1em;
  min-height: 2em;
  outline: none;
  cursor: text;
}

.bubble-text:focus {
  background: linear-gradient(rgba(47, 109, 246, 0.08), rgba(47, 109, 246, 0.08));
  border-radius: 12px;
}

.bubble-text:empty::before {
  content: attr(data-placeholder);
  color: rgba(22, 21, 19, 0.34);
}

.resize-handle {
  position: absolute;
  right: -10px;
  bottom: -10px;
  z-index: 12;
  width: 24px;
  height: 24px;
  border: 3px solid var(--blue);
  border-radius: 50%;
  background: #fff;
  cursor: nwse-resize;
}

.tool-dock {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.dock-button,
.icon-button,
.panel-button,
.panel-close,
.template-card {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.dock-button {
  min-height: 42px;
  padding: 0 13px;
  border-radius: 11px;
  font-weight: 800;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 11px;
}

.dock-button.primary,
.icon-button.is-active,
.panel-button.primary {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.dock-divider {
  width: 1px;
  height: 28px;
  background: var(--line);
}

.zoom-label {
  width: 50px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.inspector {
  position: absolute;
  top: 18px;
  right: 18px;
  bottom: 84px;
  z-index: 45;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(360px, calc(100vw - 36px));
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  opacity: 0;
  transform: translateX(calc(100% + 24px));
  transition: transform 160ms ease, opacity 160ms ease;
  pointer-events: none;
}

.inspector.is-open {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.panel-close {
  align-self: flex-end;
  width: 40px;
  height: 40px;
  border-radius: 10px;
}

.inspector-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hint-section p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.panel-button {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 10px;
}

.panel-button.danger {
  color: var(--red);
}

.panel-button:disabled,
.dock-button:disabled,
.icon-button:disabled,
input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
}

.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.field input {
  height: 40px;
  padding: 0 10px;
}

.color-field input {
  width: 64px;
  padding: 3px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.template-card {
  display: grid;
  min-height: 94px;
  place-items: center;
  gap: 8px;
  border-radius: 10px;
}

.mini-person {
  position: relative;
  display: block;
  width: 48px;
  height: 58px;
}

.mini-person::before,
.mini-person::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.mini-person::before {
  top: 0;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--ink);
}

.mini-person::after {
  top: 24px;
  width: 12px;
  height: 30px;
  border-radius: 999px;
  background: var(--ink);
}

.mini-person.full {
  background: none;
}

.mini-person.bust {
  height: 48px;
}

.mini-person.close::before {
  top: 2px;
  width: 36px;
  height: 36px;
}

.mini-person.close::after {
  top: 43px;
  width: 16px;
  height: 10px;
}

.drop-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 80;
  display: none;
  padding: 22px 30px;
  border: 2px dashed var(--blue);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  color: var(--blue);
  font-weight: 900;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.drop-hint.is-visible {
  display: block;
}

.is-panning .whiteboard,
.is-moving .whiteboard,
.is-rotating .whiteboard {
  cursor: grabbing;
}

.is-resizing .whiteboard {
  cursor: nwse-resize;
}

@media (max-width: 720px) {
  .tool-dock {
    right: 10px;
    bottom: 10px;
    left: 10px;
    overflow-x: auto;
  }

  .dock-button,
  .icon-button {
    flex: 0 0 auto;
  }

  .inspector {
    top: 10px;
    right: 10px;
    bottom: 76px;
    width: calc(100vw - 20px);
  }
}
