:root {
  color-scheme: light;
  --bg: #f7fbfb;
  --panel: #ffffff;
  --panel-soft: #eef8f5;
  --text: #21313a;
  --muted: #66757f;
  --line: #dbe8e7;
  --accent: #2a9d8f;
  --accent-strong: #1b7f74;
  --accent-soft: #dff5f0;
  --danger: #e76f51;
  --shadow: 0 10px 24px rgba(36, 70, 78, 0.13);
  --canvas-bg: #fffef8;
}

body.dark {
  color-scheme: dark;
  --bg: #151c22;
  --panel: #202a32;
  --panel-soft: #263640;
  --text: #edf6f7;
  --muted: #a7b6bd;
  --line: #3b4a53;
  --accent: #8ecae6;
  --accent-strong: #b7e4f6;
  --accent-soft: #183744;
  --danger: #ff9a76;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
  --canvas-bg: #faf6e9;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  background:
    linear-gradient(120deg, rgba(142, 202, 230, 0.13), transparent 34%),
    linear-gradient(240deg, rgba(244, 162, 97, 0.12), transparent 28%),
    var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

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

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.02rem, 2vw, 1.45rem);
  line-height: 1.2;
}

#statusText {
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 4px;
}

.top-actions,
.action-row,
.tool-row,
.settings-row,
.modal-actions,
.modal-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.board-wrap {
  min-height: 0;
}

.canvas-card {
  position: relative;
  height: 100%;
  overflow: hidden;
  border-radius: 18px;
  background: var(--canvas-bg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  touch-action: none;
}

#boardCanvas,
#previewCanvas,
.sticky-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#boardCanvas {
  z-index: 1;
}

.sticky-layer {
  z-index: 2;
  pointer-events: none;
}

.preview-canvas {
  z-index: 3;
  pointer-events: none;
}

.control-panel {
  display: grid;
  gap: 10px;
  padding: 10px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.tool-row {
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.tool-row::-webkit-scrollbar {
  display: none;
}

.tool-button,
.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  color: var(--text);
  background: var(--panel-soft);
  box-shadow: 0 4px 12px rgba(38, 70, 83, 0.1);
  font-size: 1.25rem;
}

.tool-button.active,
.icon-button.active {
  color: #ffffff;
  background: var(--accent);
  outline: 3px solid var(--accent-soft);
}

.settings-row {
  align-items: stretch;
  overflow-x: auto;
  padding-bottom: 2px;
}

.field {
  display: grid;
  gap: 4px;
  min-width: 92px;
  padding: 8px 10px;
  border-radius: 14px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.74rem;
}

.range-field {
  min-width: 168px;
}

.field input,
.field select {
  width: 100%;
}

input[type="color"] {
  min-height: 34px;
  padding: 2px;
  border: 0;
  border-radius: 10px;
  background: transparent;
}

input[type="range"] {
  accent-color: var(--accent);
}

select,
textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
}

.text-button {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 14px;
  background: var(--panel-soft);
  color: var(--text);
  box-shadow: 0 4px 12px rgba(38, 70, 83, 0.09);
  white-space: nowrap;
}

.text-button.primary {
  color: #ffffff;
  background: var(--accent);
}

.text-button.danger {
  color: #ffffff;
  background: var(--danger);
}

.action-row {
  overflow-x: auto;
  padding-bottom: 2px;
}

.sticky-note {
  position: absolute;
  min-width: 118px;
  max-width: 210px;
  min-height: 86px;
  padding: 14px 34px 14px 14px;
  border-radius: 14px 14px 18px 14px;
  color: #263238;
  box-shadow: 0 10px 18px rgba(41, 50, 65, 0.18);
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.sticky-note::after {
  content: "";
  position: absolute;
  right: 10px;
  bottom: 8px;
  width: 28px;
  height: 14px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.32);
  transform: rotate(-18deg);
}

.sticky-note .edit-sticky {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 28px;
  height: 28px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.58);
  color: #263238;
}

.modal {
  width: min(92vw, 440px);
  border: 0;
  padding: 0;
  border-radius: 22px;
  background: transparent;
  color: var(--text);
}

.modal.wide {
  width: min(94vw, 860px);
}

.modal::backdrop {
  background: rgba(16, 24, 32, 0.48);
  backdrop-filter: blur(3px);
}

.modal-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-header {
  justify-content: space-between;
}

textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  padding: 12px;
}

.swatches {
  display: flex;
  gap: 10px;
}

.swatches button {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--swatch);
  border: 3px solid transparent;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

.swatches button.active {
  border-color: var(--accent);
}

.modal-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.hint {
  min-height: 1.3em;
  color: var(--muted);
  font-size: 0.88rem;
}

.gallery-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  max-height: min(58vh, 560px);
  overflow: auto;
}

.work-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: 16px;
  background: var(--panel-soft);
}

.work-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 12px;
  background: var(--canvas-bg);
}

.work-card time {
  color: var(--muted);
  font-size: 0.78rem;
}

.work-actions {
  display: flex;
  gap: 6px;
}

.work-actions .text-button {
  flex: 1;
  min-height: 36px;
  padding: 0 8px;
}

@media (min-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr 300px;
    grid-template-rows: auto 1fr;
    padding: 18px;
  }

  .topbar {
    grid-column: 1 / -1;
  }

  .control-panel {
    align-self: stretch;
    align-content: start;
    order: 2;
  }

  .tool-row,
  .settings-row,
  .action-row {
    flex-wrap: wrap;
    overflow: visible;
  }

  .field {
    min-width: 100%;
  }

  .range-field {
    min-width: 100%;
  }
}

@media (max-width: 520px) {
  .app-shell {
    gap: 8px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .topbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 1rem;
  }

  .canvas-card {
    border-radius: 16px;
  }

  .control-panel {
    padding: 8px;
    border-radius: 18px;
  }

  .tool-button,
  .icon-button {
    width: 42px;
    height: 42px;
  }
}
