/* Apple Pencil / iPad Safari risk prototype — local styles only, no external fonts/CDN. */

:root {
  --paper: #fffdf7;
  --paper-edge: #d9d2c0;
  --ink: #111827;
  --bg: #eceae3;
  --panel: #f6f5f0;
  --line: #c9c4b4;
  --accent: #2f5fd0;
  --ok: #1a7f37;
  --warn: #9a6700;
  --bad: #b42318;
  --muted: #5f5c52;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Prevent pull-to-refresh / rubber-banding interfering with drawing. */
body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.app-title-block {
  min-width: 0;
}

.app-header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.app-subtitle {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.save-status {
  flex: 0 0 auto;
  min-width: 190px;
  text-align: center;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  background: #e7e5dc;
  color: var(--muted);
  border: 1px solid var(--line);
  transition: background-color 160ms ease, color 160ms ease;
}

.save-status[data-state="saving"] {
  background: #fff7e0;
  color: var(--warn);
  border-color: #e5c97b;
}

.save-status[data-state="saved"] {
  background: #e4f3e8;
  color: var(--ok);
  border-color: #9ccfa8;
}

.save-status[data-state="offline"] {
  background: #fff7e0;
  color: var(--warn);
  border-color: #e5c97b;
}

.save-status[data-state="failed"] {
  background: #fde8e6;
  color: var(--bad);
  border-color: #eda29a;
}

.app-layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 12px;
  padding: 12px 16px 16px;
}

.workspace {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  padding: 6px 8px;
  border-radius: 8px;
  background: #efede4;
  border: 1px solid var(--line);
}

.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.toolbar button {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  transition: background-color 120ms ease, transform 120ms ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.toolbar button:hover:not(:disabled) {
  background: #f1efe7;
}

.toolbar button:active:not(:disabled) {
  transform: translateY(1px);
}

.toolbar button:disabled {
  opacity: 0.45;
  cursor: default;
}

.toolbar button:focus-visible,
.toggle-label input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

#clear-btn.confirming {
  background: #fde8e6;
  border-color: #eda29a;
  color: var(--bad);
}

.clear-hint {
  font-size: 13px;
  font-weight: 600;
  color: var(--bad);
}

.canvas-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.canvas-stage {
  position: relative;
  display: block;
  line-height: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.canvas-hit-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-tap-highlight-color: transparent;
}

#board {
  /* Sizing is set in JS to keep the 1600x2200 logical ratio while fitting. */
  display: block;
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(60, 54, 30, 0.14);
  touch-action: none;
  pointer-events: none;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-tap-highlight-color: transparent;
}

.diagnostics {
  min-height: 0;
  overflow: auto;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.diagnostics summary {
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 0 8px;
}

.diag-list {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.diag-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 8px;
  background: #efede4;
  border-radius: 8px;
}

.diag-row dt {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.diag-row dd {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  word-break: break-word;
}

.diag-note {
  margin: 10px 2px 0;
  font-size: 12px;
  color: var(--muted);
}

/* Small / portrait screens: stack diagnostics under the canvas. */
@media (max-width: 860px), (orientation: portrait) and (max-width: 1024px) {
  .app-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .diagnostics {
    max-height: 40vh;
  }

  .save-status {
    min-width: 0;
  }
}

/* Respect reduced motion: no transitions or animations. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }

  .toolbar button:active:not(:disabled) {
    transform: none;
  }
}
