:root {
  color-scheme: dark;
  --ink: #f6f1e8;
  --muted: #bdb7ad;
  --paper: #111211;
  --panel: #1d1e1c;
  --panel-2: #282823;
  --line: rgba(246, 241, 232, 0.16);
  --amber: #c99854;
  --teal: #6f8a80;
  --wine: #7a3b41;
  --shadow: rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body.canvas-home-mode {
  min-height: 100%;
  height: auto;
  overflow: auto;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", system-ui, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button,
a {
  color: inherit;
}

a {
  text-decoration: none;
}

button {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(246, 241, 232, 0.08);
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

button:hover,
.header-actions a:hover {
  border-color: rgba(246, 241, 232, 0.34);
  background: rgba(246, 241, 232, 0.13);
}

button:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(246, 241, 232, 0.08);
  color: var(--ink);
  outline: none;
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: rgba(201, 152, 84, 0.75);
  box-shadow: 0 0 0 3px rgba(201, 152, 84, 0.14);
}

.canvas-header {
  position: relative;
  z-index: 20;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 18, 17, 0.92);
}

.brand {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  min-width: 160px;
  font-weight: 800;
}

.brand-logo {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  object-fit: contain;
}

.brand-copy {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
}

.brand-mark {
  font-size: 1rem;
}

.brand-line {
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.header-actions button,
.header-actions a {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 12px;
  background: rgba(246, 241, 232, 0.08);
  font-size: 0.86rem;
}

.canvas-home {
  width: min(1440px, calc(100% - 56px));
  min-height: calc(100vh - 68px);
  margin: 0 auto;
  padding: clamp(48px, 7vw, 104px) 0 80px;
}

.canvas-access {
  width: min(1440px, calc(100% - 56px));
  min-height: calc(100vh - 68px);
  margin: 0 auto;
  padding: clamp(48px, 7vw, 104px) 0 80px;
}

.canvas-access-card {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(300px, 1.1fr);
  gap: 56px;
  align-items: center;
  border: 1px solid var(--line);
  padding: clamp(28px, 5vw, 64px);
  background: color-mix(in srgb, var(--panel) 82%, transparent);
}

.canvas-access-card h1 {
  margin: 8px 0 14px;
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  font-size: clamp(4rem, 10vw, 9rem);
  font-weight: 400;
  line-height: 0.95;
}

.canvas-access-card p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.7;
}

.canvas-unlock-form {
  display: grid;
  gap: 10px;
}

.credential-username {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.canvas-unlock-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.canvas-unlock-row button {
  min-width: 92px;
}

.canvas-form-message {
  min-height: 1.4em;
  margin: 0;
  color: var(--amber);
}

.canvas-home-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding-bottom: 34px;
  border-bottom: 1px solid var(--line);
}

.canvas-home-heading h1 {
  margin: 8px 0 10px;
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  font-size: clamp(3rem, 7vw, 6.8rem);
  font-weight: 400;
  line-height: 0.98;
}

.canvas-home-heading p:last-child {
  max-width: 650px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.5vw, 1.22rem);
}

.new-board-button,
.board-empty button {
  min-height: 46px;
  padding: 10px 18px;
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
  white-space: nowrap;
}

.board-library {
  padding-top: 34px;
}

.library-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.library-heading h2 {
  margin: 0;
  font-size: 1rem;
}

.library-heading span {
  color: var(--muted);
  font-size: 0.82rem;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.board-card {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--panel);
}

.board-card-open {
  width: 100%;
  display: block;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  text-align: left;
}

.board-card-open:hover {
  background: transparent;
}

.board-preview {
  min-height: 170px;
  display: grid;
  place-items: center;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px),
    var(--panel-2);
  background-size: 32px 32px;
  color: var(--muted);
  font-size: 0.82rem;
}

.board-preview.has-image {
  background-position: center;
  background-size: cover;
}

.board-card-copy {
  display: grid;
  gap: 6px;
  padding: 16px 16px 14px;
}

.board-card-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1rem;
}

.board-card-copy small {
  color: var(--muted);
  font-weight: 400;
}

.board-card-actions {
  display: flex;
  gap: 4px;
  padding: 0 12px 12px;
}

.board-card-actions button {
  min-height: 30px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
}

.board-empty {
  min-height: 300px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  border: 1px dashed var(--line);
  text-align: center;
}

.board-empty p {
  margin: 0 0 10px;
  color: var(--muted);
}

.workspace {
  height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
}

.side-panel {
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #171816;
  padding: 14px;
}

.tool-block {
  display: grid;
  gap: 10px;
  padding: 14px 0 16px;
  border-bottom: 1px solid var(--line);
}

.tool-block:first-child {
  padding-top: 0;
}

.tool-block label {
  display: grid;
  gap: 6px;
  color: rgba(246, 241, 232, 0.76);
  font-size: 0.84rem;
  font-weight: 700;
}

.eyebrow {
  margin: 0;
  color: var(--amber);
  font-size: 0.78rem;
  font-weight: 800;
}

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

.button-grid button {
  min-height: 38px;
  padding: 8px 10px;
}

.hint {
  margin: 0;
  color: rgba(246, 241, 232, 0.54);
  font-size: 0.78rem;
  line-height: 1.6;
}

.stage-wrap {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 18%, rgba(201, 152, 84, 0.1), transparent 24%),
    linear-gradient(145deg, #121412, #191b19);
}

.ink-toolbar {
  position: absolute;
  z-index: 10;
  top: 14px;
  left: 14px;
  max-width: calc(100% - 260px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  box-shadow: 0 10px 30px var(--shadow);
  backdrop-filter: blur(16px);
}

.tool-segment,
.color-swatches {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ink-toolbar button {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 0.78rem;
}

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

.color-swatch {
  width: 28px;
  min-width: 28px;
  min-height: 28px !important;
  height: 28px;
  border-radius: 50%;
  padding: 0 !important;
  background: var(--swatch) !important;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 22%, transparent);
}

.color-swatch.active {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.stroke-size {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.stroke-size input {
  width: 82px;
  padding: 0;
  accent-color: var(--amber);
  box-shadow: none;
}

.stage-toolbar {
  position: absolute;
  z-index: 5;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 8px;
  color: rgba(246, 241, 232, 0.7);
  font-size: 0.78rem;
}

.stage-toolbar span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(17, 18, 17, 0.82);
  backdrop-filter: blur(12px);
}

.viewport {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.viewport[data-tool="pen"] {
  cursor: none;
}

.viewport[data-tool="zoom"] {
  cursor: zoom-in;
}

.viewport[data-tool="eraser"] {
  cursor: none;
}

.viewport[data-tool="lasso"],
.viewport[data-tool="rect-lasso"] {
  cursor: copy;
}

.viewport[data-tool="heal"],
.viewport[data-tool="smudge"] {
  cursor: none;
}

.viewport.dragging {
  cursor: grabbing;
}

.brush-cursor {
  position: absolute;
  z-index: 9;
  left: 0;
  top: 0;
  border: 1.5px solid var(--amber);
  border-radius: 999px;
  background: color-mix(in srgb, var(--amber) 10%, transparent);
  pointer-events: none;
  mix-blend-mode: multiply;
}

.brush-cursor[data-tool="eraser"] {
  border-style: dashed;
  background: rgba(246, 241, 232, 0.32);
}

.brush-cursor[data-tool="heal"] {
  border-color: #b85b5b;
  background: rgba(184, 91, 91, 0.12);
}

.brush-cursor[data-tool="smudge"] {
  border-color: #2f6f9f;
  background: rgba(47, 111, 159, 0.12);
}

.tool-menu {
  position: fixed;
  z-index: 30;
  display: grid;
  min-width: 132px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: 0 18px 42px var(--shadow);
}

.tool-menu[hidden] {
  display: none;
}

.tool-menu button {
  min-height: 30px;
  border: 0;
  border-radius: 4px;
  padding: 5px 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.tool-menu button:hover {
  background: rgba(201, 152, 84, 0.18);
}

.tool-menu hr {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
  margin: 5px 0;
}

.selection-box {
  position: absolute;
  z-index: 4;
  border: 1px solid rgba(201, 152, 84, 0.86);
  background: rgba(201, 152, 84, 0.14);
  pointer-events: none;
}

.selection-box.lasso {
  border-style: dashed;
  border-radius: 999px;
}

.canvas-grid,
.board {
  position: absolute;
  top: 0;
  left: 0;
  width: 6000px;
  height: 4200px;
  transform-origin: 0 0;
}

.canvas-grid {
  pointer-events: none;
  background-image:
    linear-gradient(rgba(246, 241, 232, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(246, 241, 232, 0.055) 1px, transparent 1px),
    linear-gradient(rgba(246, 241, 232, 0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(246, 241, 232, 0.09) 1px, transparent 1px);
  background-position: 0 0;
  background-size: 40px 40px, 40px 40px, 200px 200px, 200px 200px;
}

.board {
  z-index: 2;
}

.item-layer,
.ink-layer {
  position: absolute;
  inset: 0;
  width: 6000px;
  height: 4200px;
}

.item-layer {
  z-index: 2;
}

.ink-layer {
  z-index: 3;
  overflow: visible;
  pointer-events: none;
}

.canvas-item {
  position: absolute;
  width: 260px;
  min-height: 132px;
  border: 1px solid rgba(246, 241, 232, 0.22);
  border-radius: 6px;
  background: rgba(29, 30, 28, 0.94);
  box-shadow: 0 18px 42px var(--shadow);
  overflow: hidden;
  user-select: none;
}

.canvas-item.selected {
  border-color: rgba(201, 152, 84, 0.9);
  box-shadow: 0 0 0 3px rgba(201, 152, 84, 0.16), 0 18px 42px var(--shadow);
}

.canvas-item.frame {
  width: 420px;
  min-height: 260px;
  background: rgba(201, 152, 84, 0.055);
  border-style: dashed;
}

.canvas-item.image {
  width: 320px;
  background: rgba(10, 11, 10, 0.92);
}

.canvas-item.note {
  background: rgba(111, 138, 128, 0.2);
}

.item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(246, 241, 232, 0.12);
  cursor: grab;
}

.item-head strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
}

.item-head span {
  flex: 0 0 auto;
  color: var(--amber);
  font-size: 0.72rem;
  font-weight: 800;
}

.item-body {
  padding: 11px 12px 14px;
  color: rgba(246, 241, 232, 0.76);
  font-size: 0.86rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.canvas-item.image .item-body {
  padding: 0;
}

.canvas-item.image img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: cover;
}

.canvas-item.image .caption {
  padding: 10px 12px 12px;
  color: rgba(246, 241, 232, 0.68);
}

.inline-editor {
  display: block;
  width: 100%;
  min-width: 0;
  margin: 0;
  border: 1px solid var(--amber);
  border-radius: 3px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: none;
  resize: vertical;
}

.item-head .inline-editor {
  padding: 4px 6px;
  font-size: 0.88rem;
  font-weight: 700;
}

.item-body > .inline-editor,
.caption > .inline-editor {
  min-height: 92px;
  padding: 8px;
  line-height: 1.55;
}

.viewport.drop-ready {
  box-shadow: inset 0 0 0 2px rgba(201, 152, 84, 0.7);
}

@media (max-width: 900px) {
  .canvas-header {
    position: sticky;
    top: 0;
    z-index: 8;
    height: auto;
    flex-wrap: wrap;
    padding: 14px;
  }

  .header-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .workspace {
    height: calc(100vh - 104px);
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .side-panel {
    padding: 12px;
  }

  .ink-toolbar {
    max-width: calc(100% - 28px);
    flex-wrap: wrap;
  }

  .stage-toolbar {
    top: auto;
    bottom: 14px;
  }

  .canvas-home {
    width: min(100% - 32px, 1440px);
    padding-top: 48px;
  }

  .canvas-access {
    width: min(100% - 32px, 1440px);
    padding-top: 48px;
  }

  .canvas-access-card {
    grid-template-columns: 1fr;
    gap: 28px;
  }

  .canvas-home-heading {
    align-items: flex-start;
  }
}

@media (max-width: 700px) {
  body:not(.canvas-home-mode) {
    overflow: hidden;
  }

  .canvas-header {
    gap: 10px;
    padding: 10px 12px;
  }

  .brand {
    min-width: 0;
  }

  .brand-copy {
    display: none;
  }

  .header-actions {
    gap: 5px;
  }

  .header-actions button,
  .header-actions a {
    min-height: 32px;
    padding: 6px 8px;
    font-size: 0.76rem;
  }

  .workspace {
    height: calc(100dvh - 98px);
    grid-template-columns: 1fr;
    grid-template-rows: minmax(116px, 28vh) minmax(0, 1fr);
  }

  .side-panel {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .tool-block {
    padding: 10px 0 12px;
  }

  .canvas-home-heading {
    display: grid;
  }

  .canvas-unlock-row {
    grid-template-columns: 1fr;
  }

  .canvas-home-heading h1 {
    font-size: 4rem;
  }

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

  .ink-toolbar {
    right: 8px;
    left: 8px;
    top: 8px;
    gap: 7px;
    padding: 6px;
  }

  .stroke-size {
    display: none;
  }

  .ink-toolbar button {
    padding-inline: 8px;
  }
}
