:root {
  color-scheme: light;
  --ink: #15365f;
  --ink-soft: #5b6f84;
  --paper: #fffefa;
  --grid: #7bd9f3;
  --grid-soft: rgba(123, 217, 243, 0.55);
  --yellow: #ffd84d;
  --yellow-soft: #fff3bd;
  --button-shadow: 4px 4px 0 rgba(21, 54, 95, 0.94);
  --panel-shadow: 5px 5px 0 rgba(21, 54, 95, 0.9), 0 16px 36px rgba(21, 54, 95, 0.2);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  overflow: hidden;
  background: #fff;
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  color: inherit;
  font: 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;
  width: 100vw;
  min-height: 100dvh;
  overflow: hidden;
}

#gridCanvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100dvh;
  cursor: default;
  touch-action: none;
  user-select: none;
}

#gridCanvas:focus-visible,
button:focus-visible {
  outline: 3px solid #217fd3;
  outline-offset: 3px;
}

.floating-tools {
  position: fixed;
  left: clamp(14px, 2.2vw, 30px);
  bottom: clamp(14px, 2.4vw, 26px);
  z-index: 20;
  display: flex;
  max-width: calc(100vw - 28px);
  align-items: center;
  gap: 10px;
  padding: 0;
  flex-wrap: wrap;
}

.tool-button,
.icon-button,
.pen-swatch,
.secondary-button,
.danger-button {
  border: 2px solid var(--ink);
  background: #fff;
  cursor: pointer;
  font-weight: 1000;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease, opacity 150ms ease;
}

.tool-button,
.icon-button {
  min-height: 48px;
  box-shadow: var(--button-shadow);
}

.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border-radius: 14px;
  font-size: 16px;
}

.icon-button {
  display: grid;
  width: 50px;
  height: 48px;
  place-items: center;
  padding: 0;
  border-radius: 14px;
}

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

.tool-button[aria-pressed="true"],
.icon-button[aria-pressed="true"],
.trace-button[aria-pressed="true"] {
  background: var(--yellow);
}

.icon-button svg {
  display: block;
  width: 25px;
  height: 25px;
  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;
}

.clear-button {
  background: #ffe8e0;
}

.save-button {
  background: #e4f7dc;
}

.pen-cluster {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 48px;
  padding: 4px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--button-shadow);
}

.pen-cluster .icon-button,
.pen-cluster .pen-swatch {
  box-shadow: none;
}

.pen-cluster .icon-button:hover,
.pen-cluster .pen-swatch:hover {
  box-shadow: none;
}

.pen-swatch {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  padding: 0;
  border-radius: 50%;
}

.pen-swatch.red {
  background: #e84855;
}

.pen-swatch.green {
  background: #25a95f;
}

.pen-swatch.blue {
  background: #247ce8;
}

.pen-swatch.black {
  background: #202933;
}

.pen-swatch.is-selected {
  outline: 3px solid var(--yellow);
  outline-offset: 3px;
}

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

.bubble {
  position: fixed;
  left: var(--bubble-left, 50vw);
  top: var(--bubble-top, 50vh);
  z-index: 30;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 12px;
  border: 2px solid var(--ink);
  border-radius: 17px;
  background: var(--paper);
  box-shadow: var(--panel-shadow);
}

.bubble::after {
  position: absolute;
  left: var(--tail-x, 50%);
  top: var(--tail-y, 100%);
  width: 16px;
  height: 16px;
  border: 2px solid var(--ink);
  border-top: 0;
  border-left: 0;
  background: var(--paper);
  content: "";
  transform: translate(-50%, -8px) rotate(45deg);
}

.bubble[data-placement="below"]::after {
  top: 0;
  border: 2px solid var(--ink);
  border-right: 0;
  border-bottom: 0;
  transform: translate(-50%, -8px) rotate(45deg);
}

.bubble-title {
  margin: 0 0 9px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 1000;
  text-align: center;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(6, 36px);
  gap: 8px;
}

.color-choice {
  display: block;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 2px solid var(--choice-stroke);
  border-radius: 9px;
  background: var(--choice-fill);
  cursor: pointer;
}

.color-choice.green {
  --choice-fill: #d7ec8b;
  --choice-stroke: #25b86b;
}

.color-choice.purple {
  --choice-fill: #c8c6df;
  --choice-stroke: #6d70aa;
}

.color-choice.yellow {
  --choice-fill: #fff7bd;
  --choice-stroke: #efc53a;
}

.color-choice.blue {
  --choice-fill: #dff3f8;
  --choice-stroke: #17a6c5;
}

.color-choice.pink {
  --choice-fill: #f5d1e2;
  --choice-stroke: #df1d88;
}

.color-choice.blank {
  --choice-fill: #ffffff;
  --choice-stroke: #8291a3;
  background:
    linear-gradient(135deg, transparent 0 45%, #8291a3 46% 54%, transparent 55% 100%),
    #ffffff;
}

.delete-bubble {
  width: 206px;
}

.pen-name-bubble {
  padding: 9px 12px;
}

.pen-name-text {
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 1000;
  white-space: nowrap;
}

.save-bubble {
  width: min(560px, calc(100vw - 24px));
}

.save-link-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.save-link-input {
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  color: var(--ink-soft);
  font: 700 13px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.save-link-input::selection {
  background: var(--yellow-soft);
  color: var(--ink);
}

.help-bubble {
  width: min(560px, calc(100vw - 24px));
  max-height: min(70vh, 540px);
  padding: 17px 19px 18px;
  overflow: auto;
  overscroll-behavior: contain;
}

.help-title {
  margin-bottom: 13px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 1000;
  text-align: center;
}

.help-content {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 22px;
}

.help-content section,
.help-content h2,
.help-content p {
  margin: 0;
}

.help-content h2 {
  margin-bottom: 4px;
  color: #d08a00;
  font-size: 14px;
  font-weight: 1000;
}

.help-content p {
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.58;
}

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

.secondary-button,
.danger-button {
  min-height: 38px;
  border-radius: 12px;
  box-shadow: 2px 2px 0 rgba(21, 54, 95, 0.9);
  font-size: 14px;
}

.secondary-button {
  background: #f4f8fb;
}

.danger-button {
  border-color: #8e3a2c;
  background: #ffe1d8;
  color: #8e3a2c;
}

@media (max-width: 720px) {
  .floating-tools {
    gap: 8px;
  }

  .tool-button {
    min-height: 43px;
    padding: 0 13px;
    font-size: 14px;
  }

  .icon-button {
    width: 44px;
    height: 43px;
  }

  .pen-cluster {
    min-height: 43px;
    gap: 5px;
  }

  .pen-swatch {
    width: 26px;
    height: 26px;
  }

  .color-grid {
    grid-template-columns: repeat(3, 38px);
  }

  .help-bubble {
    max-height: 62vh;
    padding: 15px 17px 16px;
  }

  .save-link-row {
    grid-template-columns: 1fr;
  }

  .help-content {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}
