:root {
  --bg: #F4F3F2;
  --panel: rgba(255, 255, 255, 0.94);
  --text: #1d1d1f;
  --muted: #696969;
  --line: rgba(0, 0, 0, 0.08);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.16);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  overscroll-behavior: none;
}

#board {
  display: block;
  width: 100vw;
  height: 100vh;
  background: var(--bg);
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

body.locked #board {
  cursor: grab;
}

body.panning #board {
  cursor: grabbing;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(244, 243, 242, 0.76);
  backdrop-filter: blur(10px);
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(420px, calc(100vw - 32px));
  padding: 28px;
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.modal-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.modal-card p {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.45;
}

.modal-card input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 14px;
  font-size: 16px;
  outline: none;
  background: #fff;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

button {
  border: 0;
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 800;
  cursor: pointer;
  color: #fff;
  background: #1e1e1e;
}

#closeModalBtn {
  background: #777;
}

#passwordError {
  display: block;
  min-height: 18px;
  margin-top: 10px;
  color: #b3261e;
  font-size: 13px;
}

.color-dock {
  position: fixed;
  left: -238px;
  top: 50%;
  z-index: 30;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  transition: left 180ms ease;
}

.color-dock:hover,
.color-dock.open {
  left: 0;
}

.dock-icon {
  order: 2;
  width: 44px;
  height: 86px;
  display: grid;
  place-items: center;
  border-radius: 0 22px 22px 0;
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 26px;
}

.color-panel {
  width: 238px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 22px 22px 0;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.panel-title {
  font-weight: 900;
  margin-bottom: 12px;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
  margin-bottom: 14px;
}

.color-dot {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 1px var(--line), 0 5px 14px rgba(0,0,0,.12);
}

.color-dot.active {
  outline: 3px solid #111;
}

.rgb-picker,
.line-control {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  margin-top: 12px;
}

.rgb-picker input {
  width: 54px;
  height: 54px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: transparent;
}

.line-control input {
  width: 100%;
}

.unlock-floating {
  position: fixed;
  left: 12px;
  top: 14px;
  z-index: 25;
  min-width: 142px;
  padding: 10px 13px;
  border-radius: 999px;
  background: rgba(30, 30, 30, 0.82);
  backdrop-filter: blur(8px);
  font-size: 13px;
  box-shadow: var(--shadow);
}

body:not(.locked) .unlock-floating {
  display: none;
}

.history-actions {
  position: fixed;
  left: 12px;
  bottom: 42px;
  z-index: 25;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-actions button {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 999px;
  background: rgba(30, 30, 30, 0.74);
  backdrop-filter: blur(8px);
  font-size: 20px;
  box-shadow: 0 8px 22px rgba(0,0,0,.16);
}

.history-actions button:disabled {
  opacity: 0.38;
  cursor: default;
}

.brush-dock {
  position: fixed;
  left: 50%;
  bottom: -96px;
  z-index: 30;
  transform: translateX(-50%);
  transition: bottom 180ms ease;
}

.brush-dock:hover,
.brush-dock.open {
  bottom: 0;
}

.brush-handle {
  width: 136px;
  margin: 0 auto;
  padding: 9px 14px;
  text-align: center;
  border-radius: 18px 18px 0 0;
  color: #fff;
  background: rgba(30, 30, 30, 0.92);
  font-weight: 900;
  box-shadow: var(--shadow);
}

.brush-panel {
  display: flex;
  gap: 10px;
  padding: 14px;
  border-radius: 24px 24px 0 0;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.brush-btn {
  min-width: 88px;
  height: 58px;
  padding: 8px 10px;
  background: #fff;
  color: #1e1e1e;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  gap: 3px;
}

.brush-btn span {
  font-size: 11px;
  color: #666;
  font-weight: 700;
}

.brush-btn.active {
  color: #fff;
  background: #1e1e1e;
}

.brush-btn.active span {
  color: #d6d6d6;
}

.status {
  position: fixed;
  right: 14px;
  top: 14px;
  z-index: 20;
  display: flex;
  gap: 8px;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  pointer-events: none;
}

.status span {
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(30, 30, 30, 0.8);
  backdrop-filter: blur(8px);
}

@media (max-width: 780px) {
  .status {
    right: 10px;
    top: 10px;
    flex-direction: column;
    align-items: flex-end;
    font-size: 11px;
  }

  .unlock-floating {
    left: 10px;
    top: 10px;
    min-width: 124px;
    padding: 9px 11px;
    font-size: 12px;
  }

  .color-dock {
    left: -224px;
  }

  .color-panel {
    width: 224px;
    padding: 14px;
  }

  .dock-icon {
    width: 40px;
    height: 76px;
  }

  .brush-dock {
    width: 100%;
    bottom: -104px;
  }

  .brush-panel {
    width: calc(100vw - 16px);
    margin: 0 auto;
    overflow-x: auto;
    border-radius: 20px 20px 0 0;
    padding: 12px;
  }

  .brush-btn {
    min-width: 82px;
    height: 58px;
    font-size: 12px;
  }

  .history-actions {
    bottom: 38px;
    left: 10px;
  }

  .history-actions button {
    width: 40px;
    height: 40px;
  }

  .modal-actions {
    flex-direction: column;
  }
}
