:root {
  color-scheme: light;
  --ink: #15365f;
  --ink-soft: #5b6f84;
  --paper: #fffefa;
  --grid: #7bd9f3;
  --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: #cfefff;
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.app-shell {
  position: relative;
  width: 100vw;
  min-height: 100dvh;
  overflow: hidden;
}

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

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

.control-panel {
  position: fixed;
  left: 50%;
  bottom: clamp(14px, 2.4vw, 26px);
  z-index: 20;
  display: grid;
  max-width: calc(100vw - 28px);
  gap: 10px;
  padding: 12px;
  border: 2px solid var(--ink);
  border-radius: 17px;
  background: #fff;
  box-shadow: var(--panel-shadow);
  transform: translateX(-50%);
}

.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.reflection-controls {
  justify-content: flex-start;
}

.operation-hint {
  position: fixed;
  z-index: 30;
  max-width: calc(100vw - 24px);
  padding: 7px 11px;
  border: 1px solid #dbab5c;
  border-radius: 7px;
  background: #fff5dc;
  color: #75420b;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 2px 6px #00000015;
}

.tool-button,
.icon-button,
.control-select,
.control-number {
  border: 2px solid var(--ink);
  background: #fff;
  font-weight: 1000;
}

.tool-button,
.icon-button,
.control-select,
.control-number {
  min-height: 48px;
  border-radius: 14px;
  box-shadow: var(--button-shadow);
}

.tool-button,
.control-select,
.control-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  font-size: 16px;
}

.tool-button,
.icon-button,
.control-select {
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease, opacity 150ms ease;
}

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

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

.clear-button {
  background: #ffe8e0;
}

.action-button {
  background: #dff3f8;
}

.drop-button {
  background: #d8f3dd;
}

.reflect-button {
  background: var(--yellow-soft);
}

.rotate-button {
  background: #c8c6df;
}

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

.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;
}

.side-actions {
  position: fixed;
  left: var(--side-actions-left, calc(100vw - 92px));
  top: var(--side-actions-top, 12px);
  z-index: 21;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.side-actions .tool-button,
.side-actions .icon-button {
  width: 76px;
  min-width: 76px;
  min-height: 48px;
  padding: 0 10px;
}

.control-label {
  font-size: 18px;
  font-weight: 1000;
  white-space: nowrap;
}

.control-select {
  min-width: 92px;
  appearance: auto;
}

.pivot-button {
  min-width: 76px;
}

.turn-direction-group {
  display: inline-grid;
  flex-shrink: 0;
  gap: 4px;
}

.turn-direction-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 58px;
  height: 29px;
  padding: 0;
  border: 2px solid #cddce2;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.turn-direction-button span {
  font-size: 22px;
  line-height: 1;
}

.turn-direction-button[aria-pressed="true"] {
  border-color: var(--ink);
  background: #ffdf57;
}

.turn-direction-button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.reflection-line-button {
  min-width: 76px;
  padding: 0 16px;
}

.control-number {
  width: 92px;
  text-align: center;
}

.number-field {
  display: grid;
  grid-template-columns: 70px;
  align-items: center;
  justify-items: center;
  gap: 5px;
}

.number-field .control-number {
  width: 70px;
  min-height: 40px;
  padding: 0 8px;
  border-color: #cddce2;
  border-radius: 10px;
  box-shadow: none;
  caret-color: transparent;
}

.number-stepper {
  display: grid;
  width: 34px;
  height: 26px;
  place-items: center;
  padding: 0;
  border: 2px solid #cddce2;
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 20px;
  font-weight: 1000;
  line-height: 1;
  transition: border-color 150ms ease, background 150ms ease, opacity 150ms ease;
}

.number-field.angle-field {
  gap: 2px;
}

.number-field.angle-field .control-number {
  height: 26px;
  min-height: 26px;
  border-radius: 7px;
  appearance: textfield;
  -moz-appearance: textfield;
  caret-color: auto;
}

.angle-field .control-number::-webkit-inner-spin-button,
.angle-field .control-number::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.number-stepper:hover:not(:disabled),
.number-stepper:active:not(:disabled) {
  border-color: var(--ink);
  background: var(--yellow);
}

.number-stepper:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.direction-pad {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(3, 30px);
  grid-template-rows: repeat(3, 30px);
  justify-content: start;
  gap: 4px;
}

.direction-option {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  padding: 0;
  border: 2px solid #cddce2;
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

.direction-option:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--ink);
}

.direction-option[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--yellow);
  box-shadow: 2px 2px 0 var(--ink);
}

.direction-option:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  transform: none;
}

.direction-option.up { grid-column: 2; grid-row: 1; }
.direction-option.left { grid-column: 1; grid-row: 2; }

.direction-center {
  grid-column: 2;
  grid-row: 2;
  border-radius: 8px;
  background: #edf5f7;
}

.direction-option.right { grid-column: 3; grid-row: 2; }
.direction-option.down { grid-column: 2; grid-row: 3; }

.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;
}

.pivot-choices {
  display: grid;
  grid-template-columns: repeat(4, 42px);
  gap: 8px;
}

.pivot-choice {
  width: 42px;
  height: 42px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  box-shadow: 2px 2px 0 rgba(21, 54, 95, 0.9);
  cursor: pointer;
  font-size: 18px;
  font-weight: 1000;
}

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

.number-pad {
  width: 154px;
  padding: 8px;
}

.number-pad-display {
  display: grid;
  min-height: 32px;
  margin-bottom: 6px;
  place-items: center;
  border: 2px solid #cddce2;
  border-radius: 10px;
  background: #f7fbfd;
  color: var(--ink);
  font-size: 18px;
  font-weight: 1000;
}

.number-pad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.number-pad-grid button {
  display: grid;
  min-height: 32px;
  place-items: center;
  border: 1.5px solid #cddce2;
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 1000;
}

.number-pad-grid button:hover,
.number-pad-grid button:active {
  border-color: var(--ink);
  background: #edf7fb;
}

.number-pad-grid .number-pad-confirm {
  grid-column: 1 / -1;
  background: #edfae9;
  color: #2b6d23;
}

.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;
}

@media (max-width: 820px) {
  .control-panel {
    right: 12px;
    left: 12px;
    max-width: none;
    padding: 10px;
    transform: none;
  }

  .control-row {
    gap: 8px;
  }

  .tool-button,
  .control-select,
  .control-number {
    min-height: 43px;
    padding: 0 12px;
    font-size: 14px;
  }

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

  .side-actions {
    gap: 6px;
  }

  .side-actions .tool-button,
  .side-actions .icon-button {
    width: 64px;
    min-width: 64px;
    min-height: 43px;
  }

  .control-label {
    font-size: 15px;
  }

  .control-number {
    width: 74px;
  }

  .number-field {
    grid-template-columns: 62px;
  }

  .number-field .control-number {
    width: 62px;
    min-height: 39px;
  }

  .number-stepper {
    width: 32px;
    height: 26px;
  }

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

@media (max-width: 520px) {
  .control-panel {
    gap: 8px;
  }

  .control-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto minmax(64px, 0.8fr) auto;
  }

  .reflection-controls {
    display: flex;
    justify-content: flex-start;
  }

  .reflection-controls .reflection-line-button {
    width: auto;
    flex: 0 0 auto;
  }

  .control-row .tool-button {
    grid-column: 1 / -1;
  }

  .translation-controls {
    grid-template-columns: auto 90px minmax(0, 1fr) auto;
    grid-template-areas:
      "prefix pad label label"
      "prefix pad number unit"
      "translate translate translate translate";
    align-items: center;
  }

  .translation-controls .direction-prefix {
    grid-area: prefix;
  }

  .translation-controls .direction-pad {
    grid-area: pad;
    grid-template-columns: repeat(3, 28px);
    grid-template-rows: repeat(3, 28px);
    gap: 3px;
  }

  .translation-controls .direction-option {
    width: 28px;
    height: 28px;
    font-size: 18px;
  }

  .translation-controls .translation-label {
    grid-area: label;
    align-self: end;
  }

  .translation-controls .number-field {
    grid-area: number;
    justify-self: end;
  }

  .translation-controls .translation-unit {
    grid-area: unit;
  }

  .translation-controls #translateButton {
    grid-area: translate;
  }

  .control-select,
  .control-number,
  .pivot-button {
    width: 100%;
    min-width: 0;
  }

  .number-field {
    width: max-content;
  }
}

@media (max-width: 360px) {
  .translation-controls .number-field {
    grid-template-columns: 54px;
    gap: 4px;
  }

  .translation-controls .number-field .control-number {
    width: 54px;
  }

  .translation-controls .number-stepper {
    width: 28px;
  }
}
