:root {
  color-scheme: light;
  --ink: #15365f;
  --ink-dark: #202933;
  --grid: #7bd9f3;
  --paper: #ffffff;
  --stage: #eef9fc;
  --yellow: #ffd84d;
  --green-soft: #e4f7dc;
  --coral-soft: #ffe8e0;
  --shadow: 0 20px 42px rgba(21, 54, 95, 0.2);
  --button-shadow: 4px 4px 0 rgba(21, 54, 95, 0.94);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  min-height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 216, 77, 0.16), transparent 34%),
    var(--stage);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  position: relative;
  display: flex;
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  align-items: safe center;
  justify-content: safe center;
  padding: 20px 112px 92px 24px;
  overflow: auto;
  overscroll-behavior: contain;
}

.page-frame {
  position: relative;
  width: var(--page-width, min(210mm, calc((100dvh - 124px) * 210 / 297), calc(100vw - 136px)));
  aspect-ratio: 210 / 297;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid rgba(21, 54, 95, 0.28);
  background: var(--paper);
  box-shadow: var(--shadow);
}

#drawingCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: var(--canvas-cursor, crosshair);
  user-select: none;
}

#drawingCanvas:focus-visible,
button:focus-visible,
.text-editor:focus-visible {
  outline: 3px solid #217fd3;
  outline-offset: 3px;
}

.text-editor {
  --editor-font-size: 18px;
  position: absolute;
  z-index: 5;
  min-width: calc(var(--editor-font-size) * 2);
  height: calc(var(--editor-font-size) * 1.3);
  padding: 0 3px;
  border: 1px solid rgba(21, 54, 95, 0.82);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink-dark);
  font-size: var(--editor-font-size);
  font-weight: 600;
  line-height: 1;
}

.floating-tools {
  position: fixed;
  left: 50%;
  bottom: clamp(14px, 2.5vw, 24px);
  z-index: 20;
  display: flex;
  max-width: calc(100vw - 28px);
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  transform: translateX(-50%);
}

.tool-button,
.icon-button {
  min-height: 46px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--button-shadow);
  cursor: pointer;
  font-weight: 1000;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease, opacity 150ms ease;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  font-size: 16px;
  white-space: nowrap;
}

.icon-button {
  display: grid;
  width: 48px;
  height: 46px;
  place-items: center;
  padding: 0;
}

.icon-button svg {
  display: block;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.25;
}

.help-button span {
  display: block;
  font-size: 25px;
  font-weight: 1000;
  line-height: 1;
}

.tool-button:hover,
.icon-button:hover {
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0 rgba(21, 54, 95, 0.94);
}

.tool-button:active,
.icon-button:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 rgba(21, 54, 95, 0.94);
}

.tool-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  transform: none;
}

.delete-button[aria-pressed="true"] {
  background: var(--yellow);
}

.clear-button {
  background: var(--coral-soft);
}

.download-button {
  background: var(--green-soft);
}

.bubble {
  position: fixed;
  z-index: 30;
  max-width: min(430px, calc(100vw - 32px));
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--button-shadow), 0 16px 34px rgba(21, 54, 95, 0.16);
}

.help-bubble {
  left: 50%;
  bottom: clamp(78px, 10vw, 92px);
  padding: 16px 18px;
  transform: translateX(-50%);
}

.help-bubble h2 {
  margin: 0 0 10px;
  font-size: 18px;
  line-height: 1.25;
}

.help-bubble ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 19px;
  color: var(--ink-dark);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.55;
}

.zoom-control {
  position: fixed;
  right: clamp(12px, 2vw, 28px);
  top: 50%;
  z-index: 20;
  display: flex;
  width: 54px;
  min-height: 244px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 8px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--button-shadow);
  transform: translateY(-50%);
}

.zoom-slider {
  width: 28px;
  height: 178px;
  accent-color: var(--ink);
  cursor: pointer;
  direction: rtl;
  writing-mode: vertical-lr;
}

.zoom-value {
  display: block;
  min-width: 36px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 1000;
  line-height: 1;
  text-align: center;
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px 68px 88px 12px;
  }

  .page-frame {
    width: var(--page-width, min(calc((100dvh - 112px) * 210 / 297), calc(100vw - 80px)));
  }

  .tool-button {
    padding: 0 14px;
    font-size: 14px;
  }

  .zoom-control {
    right: 8px;
    width: 48px;
    min-height: 206px;
    padding: 10px 6px;
  }

  .zoom-slider {
    height: 146px;
  }
}

@media print {
  @page {
    size: A4;
    margin: 0;
  }

  html,
  body {
    width: 210mm;
    height: 297mm;
    background: #ffffff;
  }

  .app-shell {
    display: block;
    width: 210mm;
    min-height: 297mm;
    padding: 0;
    overflow: visible;
  }

  .page-frame {
    width: 210mm;
    height: 297mm;
    border: 0;
    box-shadow: none;
  }

  .floating-tools,
  .zoom-control,
  .bubble,
  .text-editor {
    display: none !important;
  }
}
