:root {
  color-scheme: light;
  --ink: #241f21;
  --muted: #6d6465;
  --paper: #fffaf2;
  --panel: #ffffff;
  --line: #241f21;
  --title-yellow: #f2bd22;
  --accent: #2f8f83;
  --accent-strong: #1f6d64;
  --warn: #b73a47;
  --shadow: 0 18px 45px rgba(38, 31, 33, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, #fff8df 0%, #edf8f5 46%, #f9eef2 100%);
}

button,
input,
select {
  font: inherit;
}

button,
.import-save {
  min-height: 40px;
  border: 1px solid rgba(36, 31, 33, 0.16);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

button:hover,
.import-save:hover {
  transform: translateY(-1px);
  border-color: rgba(36, 31, 33, 0.36);
}

.home-screen,
.theme-screen,
.custom-screen {
  min-height: 100vh;
  padding: clamp(18px, 4vw, 42px);
}

.home-header h1 {
  margin: 0;
  color: var(--title-yellow);
  font-size: clamp(2rem, 5vw, 4.5rem);
  line-height: 1;
  text-shadow: 0 2px 0 rgba(36, 31, 33, 0.12);
}

.home-center {
  display: grid;
  place-items: center;
  gap: 18px;
  min-height: calc(100vh - 132px);
}

.home-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 180px));
  gap: 14px;
  align-items: center;
}

.home-action {
  width: 100%;
  min-height: 58px;
  border: 2px solid rgba(36, 31, 33, 0.14);
  background: rgba(255, 255, 255, 0.9);
  font-size: 1.05rem;
  font-weight: 800;
}

.theme-menu {
  appearance: none;
  text-align: center;
  text-align-last: center;
  padding: 0 18px;
  cursor: pointer;
}

.home-join-panel {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 130px;
  gap: 10px;
}

.home-join-status {
  grid-column: 1 / -1;
  text-align: center;
}

.theme-header {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: clamp(18px, 3vw, 32px);
}

.theme-header h1 {
  margin: 0;
  color: var(--title-yellow);
  font-size: clamp(2rem, 4vw, 3.5rem);
}

.theme-header button {
  min-width: 82px;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
}

.theme-card {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 16px;
  min-height: 260px;
  border: 1px solid rgba(36, 31, 33, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 16px 36px rgba(38, 31, 33, 0.1);
}

.theme-card svg,
.theme-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  background: #fffaf2;
}

.theme-card img {
  display: block;
  object-fit: contain;
}

.theme-card strong {
  font-size: 1.05rem;
}

.custom-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(240px, 320px);
  gap: clamp(18px, 3vw, 34px);
  align-items: center;
  min-height: calc(100vh - 132px);
}

.custom-empty-canvas {
  display: grid;
  place-items: center;
  width: min(100%, 78vh);
  aspect-ratio: 1;
  justify-self: center;
  border: 2px dashed rgba(36, 31, 33, 0.2);
  border-radius: 8px;
  background: #fffaf2;
  box-shadow: 0 0 0 10px #fff, 0 16px 40px rgba(38, 31, 33, 0.12);
}

.custom-empty-canvas span {
  color: rgba(36, 31, 33, 0.26);
  font-size: clamp(1.5rem, 4vw, 3rem);
  font-weight: 900;
}

.custom-panel {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid rgba(36, 31, 33, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
}

.custom-file-visible {
  width: 100%;
  min-height: 46px;
  padding: 10px;
  border: 1px solid rgba(36, 31, 33, 0.16);
  border-radius: 8px;
  background: #fff;
}

.hidden-control {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  min-height: 100vh;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  background: rgba(255, 255, 255, 0.86);
  border-right: 1px solid rgba(36, 31, 33, 0.12);
  backdrop-filter: blur(16px);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.1;
}

.brand p,
.small-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel-section {
  display: grid;
  gap: 10px;
}

.field-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.room-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 8px;
}

.room-row-three {
  grid-template-columns: minmax(0, 1fr) 62px 62px;
}

input[type="text"],
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(36, 31, 33, 0.16);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

input[type="color"] {
  width: 100%;
  height: 42px;
  padding: 3px;
  border: 1px solid rgba(36, 31, 33, 0.16);
  border-radius: 8px;
  background: #fff;
}

.presence {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #b8b0ad;
}

.dot.online {
  background: #20a66b;
  box-shadow: 0 0 0 5px rgba(32, 166, 107, 0.12);
}

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

.tool {
  min-width: 0;
  font-weight: 700;
}

.tool.active {
  background: var(--ink);
  color: white;
}

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

.swatch {
  aspect-ratio: 1;
  min-height: 34px;
  border-radius: 8px;
  border: 2px solid rgba(36, 31, 33, 0.14);
}

.swatch.active {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 3px #fff;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(36, 31, 33, 0.1);
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2f8f83, #e3a72f);
}

.actions {
  grid-template-columns: 1fr 1fr;
}

.actions button,
.import-save {
  padding: 0 10px;
  text-align: center;
  display: grid;
  place-items: center;
}

.danger {
  color: var(--warn);
}

#importStateInput {
  display: none;
}

.file-input {
  display: none;
}

.wide {
  width: 100%;
}

.canvas-area {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  padding: 24px;
}

.top-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  color: var(--muted);
}

.top-strip strong {
  display: block;
  color: var(--ink);
  font-size: 1.1rem;
}

.top-strip span,
#lastAction {
  font-size: 0.92rem;
}

.artboard {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: clamp(8px, 2vw, 24px);
  border: 1px solid rgba(36, 31, 33, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
  box-shadow: var(--shadow);
}

.coloring-page {
  display: block;
  width: min(100%, 82vh);
  max-height: calc(100vh - 130px);
  aspect-ratio: 1;
  background: var(--paper);
  border-radius: 8px;
  box-shadow: 0 0 0 10px #fff, 0 16px 40px rgba(38, 31, 33, 0.18);
}

.upload-canvas {
  cursor: crosshair;
  object-fit: contain;
}

.coloring-page [data-region] {
  fill: #fffdf8;
  stroke: var(--line);
  stroke-width: 0;
  cursor: crosshair;
}

.coloring-page [data-region]:hover {
  filter: brightness(0.96);
}

.line-art {
  fill: none;
  stroke: var(--line);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.line-art circle,
.line-art ellipse,
.line-art rect {
  fill: none;
}

@media (max-width: 820px) {
  .home-actions,
  .home-join-panel {
    grid-template-columns: 1fr;
    width: min(100%, 340px);
  }

  .custom-layout {
    grid-template-columns: 1fr;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    border-right: 0;
    border-bottom: 1px solid rgba(36, 31, 33, 0.12);
  }

  .canvas-area {
    padding: 16px;
  }

  .top-strip {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .coloring-page {
    width: min(100%, 88vh);
    max-height: none;
  }
}
