:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #17202a;
  --muted: #64748b;
  --line: #cbd5e1;
  --panel: #ffffff;
  --accent: #1e7a78;
  --accent-strong: #125b59;
  --blue: #25415f;
  --paper: #f8fafc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  min-height: 100vh;
  color: var(--ink);
  background: #e9eef3;
}

body.auth-pending .app-shell {
  display: none;
}

body:not(.auth-pending) .auth-gate {
  display: none;
}

body.readonly-share .toolbar,
body.readonly-share .canvas-menu,
body.readonly-share .cloud-panel {
  display: none;
}

body.readonly-share .app-shell {
  grid-template-columns: minmax(0, 1fr);
}

body.readonly-share .topbar {
  justify-content: space-between;
}

body.readonly-share #board {
  cursor: default;
}

button,
input,
select {
  font: inherit;
}

.auth-gate {
  display: grid;
  width: 100vw;
  height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 16% 20%, rgba(30, 122, 120, 0.12), transparent 34%),
    linear-gradient(135deg, #eef4f7 0%, #e7edf2 48%, #f7fafc 100%);
}

.auth-card {
  display: grid;
  grid-template-columns: minmax(0, 320px) minmax(260px, 430px);
  align-items: center;
  gap: 24px;
  width: min(820px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.16);
}

.auth-card-body {
  display: grid;
  gap: 14px;
}

.auth-brand-mark {
  display: block;
  width: 52px;
  height: 52px;
  border-radius: 8px;
}

.auth-card h1 {
  margin: 0;
  font-size: 24px;
}

.auth-card p,
.auth-status {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.auth-card p {
  margin: 0;
}

.auth-card-body .google-login-button {
  width: 100%;
  margin-top: 6px;
}

.auth-preview-image {
  width: 100%;
  min-width: 0;
  border: 1px solid #d5e2eb;
  border-radius: 8px;
  background: #edf3f6;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.72);
}

.auth-status:empty {
  display: none;
}

.google-login-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid #747775;
  border-radius: 999px;
  color: #1f1f1f;
  background: #fff;
  font-family: Roboto, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  cursor: pointer;
}

.google-login-button:hover:not(:disabled) {
  background: #f8fafd;
  border-color: #747775;
}

.google-login-button:active:not(:disabled) {
  background: #f1f3f4;
}

.google-login-button:focus-visible {
  outline: 3px solid rgba(66, 133, 244, 0.35);
  outline-offset: 2px;
}

.google-login-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.google-login-button.compact {
  min-height: 34px;
  gap: 8px;
  padding: 0 12px;
}

.google-g-mark,
.google-g-mark svg {
  display: block;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

@media (max-width: 720px) {
  .auth-gate {
    padding: 18px;
  }

  .auth-card {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
    padding: 22px;
  }

  .auth-preview-image {
    order: -1;
  }
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: block;
  border-radius: 8px;
  flex: 0 0 auto;
}

h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

p {
  margin: 0;
}

.brand p,
.paste-box p,
.status,
.beta-panel p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.beta-panel {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #b9d9d6;
  border-radius: 8px;
  background: #f1fbfa;
}

.beta-heading,
.beta-links {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.beta-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.beta-panel a {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.beta-panel a:hover {
  text-decoration: underline;
}

.tool-section {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.tool-button,
.wide-button,
.primary-button,
.account-button,
.file-button,
.menu-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

.tool-button {
  font-size: 20px;
  font-weight: 700;
}

.tool-button.is-active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.active-tool-label {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef7f6;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
}

.wide-button {
  grid-column: span 2;
  font-weight: 700;
}

.export-control {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.export-control label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.export-control select {
  width: 100%;
}

.export-control .wide-button {
  grid-column: 1 / -1;
  width: 100%;
}

.primary-button {
  width: 100%;
  color: #fff;
  border-color: var(--accent-strong);
  background: var(--accent);
  font-weight: 800;
}

.danger-button {
  color: #b42318;
  border-color: #f3b3ad;
  background: #fff5f4;
}

.file-button {
  display: grid;
  width: 100%;
  place-items: center;
  color: var(--accent-strong);
  background: #eef7f6;
  font-weight: 800;
}

.file-button input {
  display: none;
}

.control-group {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.control-group label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.group-title {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.field-grid label {
  display: grid;
  gap: 4px;
}

select,
.number-field,
#unitScale,
.canvas-name-input {
  width: 96px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.canvas-panel label {
  display: grid;
  gap: 6px;
}

.canvas-menu-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.canvas-menu-panel select,
.canvas-name-input {
  width: 100%;
  padding: 0 8px;
}

.canvas-menu-panel .wide-button {
  grid-column: 1 / -1;
  width: 100%;
}

.share-url-output {
  width: 100%;
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid #b9d9d6;
  border-radius: 6px;
  background: #f1fbfa;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.number-field {
  width: 100%;
  padding: 0 8px;
}

.compact-actions {
  grid-template-columns: 1fr 1fr;
}

.mini-button {
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.layer-list {
  display: grid;
  gap: 6px;
}

.layer-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: grab;
}

.layer-item:active {
  cursor: grabbing;
}

.layer-item.is-dragging {
  opacity: 0.45;
}

.layer-item.is-drop-before {
  box-shadow: inset 0 3px 0 var(--accent);
}

.layer-item.is-drop-after {
  box-shadow: inset 0 -3px 0 var(--accent);
}

.layer-item.is-active {
  border-color: var(--accent);
  background: #eef7f6;
}

.layer-radio,
.layer-visible {
  display: flex !important;
  justify-content: flex-start !important;
  gap: 6px;
  min-width: 0;
}

.layer-radio span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-name {
  cursor: text;
}

.layer-name-input {
  width: 100%;
  min-width: 0;
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.panel-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.cloud-panel {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex: 0 0 320px;
  width: 320px;
}

.cloud-copy {
  display: grid;
  gap: 2px;
  width: 190px;
  min-width: 190px;
  text-align: right;
}

.cloud-state {
  display: block;
  min-height: 18px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  line-height: 18px;
}

.cloud-account {
  display: block;
  min-height: 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 16px;
  overflow-wrap: anywhere;
}

.account-button {
  min-height: 34px;
  padding: 0 12px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  background: #eef7f6;
}

.account-button.google-login-button {
  color: #1f1f1f;
  background: #fff;
  border-color: #747775;
  font-size: 13px;
  font-weight: 500;
}

.cloud-panel .account-button[hidden] {
  display: none;
}

.symbol-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: 250px;
  overflow: auto;
  padding-right: 2px;
}

.symbol-panel[hidden] {
  display: none;
}

.symbol-option {
  display: grid;
  gap: 4px;
  min-height: 82px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.symbol-option.is-active {
  border-color: var(--accent);
  background: #eef7f6;
  color: var(--accent-strong);
}

.symbol-option svg {
  width: 100%;
  height: 42px;
}

.wide-button:disabled,
.number-field:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

input[type="color"] {
  width: 54px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.paste-box {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.workspace-wrap {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  min-height: 58px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.canvas-menu {
  position: relative;
  flex: 0 0 auto;
}

.menu-button {
  min-height: 34px;
  padding: 0 14px;
  color: var(--accent-strong);
  background: #eef7f6;
  font-size: 13px;
  font-weight: 800;
}

.menu-button[aria-expanded="true"] {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.canvas-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 30;
  display: grid;
  gap: 10px;
  width: 280px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 16px 42px rgba(15, 23, 42, 0.16);
}

.canvas-menu-section {
  display: grid;
  gap: 10px;
}

.canvas-menu-section + .canvas-menu-section {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

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

.selection-summary {
  flex: 0 0 auto;
  min-width: 150px;
}

#positionLabel {
  margin-left: 12px;
  color: var(--muted);
  font-size: 13px;
}

.distance-readout {
  flex: 1 1 auto;
  color: var(--blue);
  font-size: 14px;
  font-weight: 800;
  text-align: right;
}

.workspace-frame {
  position: relative;
  min-height: 0;
  overflow: auto;
  background: #dfe7ef;
}

.workspace-frame.is-dragging {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

#board {
  display: block;
  min-width: 1100px;
  min-height: 700px;
  outline: none;
  cursor: crosshair;
}

.inline-text-editor {
  position: absolute;
  z-index: 15;
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  gap: 6px;
  align-items: center;
  min-width: 240px;
  padding: 6px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
}

.inline-text-editor[hidden] {
  display: none;
}

.inline-text-editor input {
  min-width: 0;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.inline-text-editor > input {
  padding: 0 7px;
}

.inline-text-editor label {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.inline-text-editor label input {
  width: 58px;
  padding: 0 4px;
}

.shape {
  cursor: move;
}

.shape.is-locked {
  cursor: not-allowed;
}

.shape text {
  cursor: text;
  user-select: none;
}

.shape.is-locked text {
  cursor: not-allowed;
}

.selection-box,
.marquee-box {
  fill: none;
  stroke: #1b75d0;
  stroke-width: 2;
  stroke-dasharray: 6 4;
  pointer-events: none;
}

.resize-handle {
  fill: #ffffff;
  stroke: #1b75d0;
  stroke-width: 2;
  cursor: nwse-resize;
}

.resize-handle[data-handle="ne"],
.resize-handle[data-handle="sw"] {
  cursor: nesw-resize;
}

.resize-handle[data-handle="n"],
.resize-handle[data-handle="s"] {
  cursor: ns-resize;
}

.resize-handle[data-handle="e"],
.resize-handle[data-handle="w"] {
  cursor: ew-resize;
}

.rotate-stem {
  stroke: #1b75d0;
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
  pointer-events: none;
}

.rotate-handle {
  fill: #ffffff;
  stroke: #1b75d0;
  stroke-width: 2;
  cursor: grab;
}

.rotate-handle:active {
  cursor: grabbing;
}

.corner-radius-handle {
  fill: #f08a24;
  stroke: #ffffff;
  stroke-width: 2;
  cursor: move;
}

.marquee-box {
  fill: rgba(27, 117, 208, 0.12);
}

.shape-preview {
  fill-opacity: 0.3;
  stroke-dasharray: 6 4;
  pointer-events: none;
}

.rotation-angle-label {
  fill: #1b496f;
  stroke: #ffffff;
  stroke-width: 4;
  paint-order: stroke fill;
  font-size: 18px;
  font-weight: 900;
  pointer-events: none;
}

.measure-line {
  stroke: var(--accent);
  stroke-width: 2;
  marker-start: url(#arrowStart);
  marker-end: url(#arrowEnd);
  pointer-events: none;
}

.measure-zero-marker {
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  pointer-events: none;
}

.measure-guide {
  stroke: #8aa5a5;
  stroke-width: 1;
  stroke-dasharray: 5 5;
  pointer-events: none;
}

.measure-label {
  fill: var(--accent-strong);
  font-size: 14px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 5px;
  stroke-linejoin: round;
  cursor: pointer;
  pointer-events: auto;
}

.measure-label:hover {
  fill: #0f4e4c;
  text-decoration: underline;
}

.center-guide {
  stroke: #d94747;
  stroke-width: 1.5;
  stroke-dasharray: 8 5;
  pointer-events: none;
}

.edge-overlap-guide {
  stroke: #f08a24;
  stroke-width: 4;
  stroke-linecap: round;
  pointer-events: none;
}

.context-menu {
  position: fixed;
  z-index: 30;
  display: grid;
  gap: 4px;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.2);
}

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

.context-menu button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.context-menu button:hover {
  background: #eef7f6;
}

.context-menu button:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.5;
}

.context-menu button:disabled:hover {
  background: transparent;
}

#selfTestPanel {
  position: fixed;
  z-index: 20;
  right: 18px;
  bottom: 18px;
  width: min(360px, calc(100vw - 36px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 42px rgba(15, 23, 42, 0.18);
  font-size: 13px;
}

#selfTestPanel ul {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

#selfTestPanel li[data-pass="true"] {
  color: var(--accent-strong);
}

#selfTestPanel li[data-pass="false"] {
  color: #b42318;
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .toolbar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
