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

:root {
  --paper: #f0ebe0;
  --ink: #111;
  --answer-ink: #444;
  --ui-gray: #888;
  --ui-light: #ccc;
  --ui-bg: #f5f0e8;
  --font-hand: 'Caveat', 'Kalam', cursive;
  --grid-color: rgba(0,0,0,0.06);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  font-family: var(--font-hand);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

/* Floating Action Buttons */
.fab {
  position: fixed;
  z-index: 100;
  font-family: var(--font-hand);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.fab:active {
  opacity: 0.6;
}

.fab-right {
  bottom: 24px;
  right: 24px;
  background: var(--ui-bg);
  color: var(--ink);
  padding: 12px 24px;
  border-radius: 28px;
  border: 2px solid var(--ink);
  box-shadow: 2px 3px 0 rgba(0,0,0,0.08);
  opacity: 0.65;
}

.fab-right:hover { opacity: 0.9; }

.fab-left {
  bottom: 24px;
  background: var(--ui-bg);
  color: var(--ink);
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid var(--ink);
  box-shadow: 2px 3px 0 rgba(0,0,0,0.08);
  opacity: 0.55;
  font-size: 22px;
}

.fab-left:hover { opacity: 0.85; }

.fab-left-1 { left: 24px; }
.fab-left-2 { left: 88px; }

.fab-top-right {
  top: 16px;
  right: 16px;
  background: transparent;
  color: var(--ui-gray);
  font-size: 28px;
  opacity: 0.5;
  border: none;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab-top-right:hover { opacity: 0.8; }

.fab-top-left {
  top: 16px;
  left: 16px;
  background: transparent;
  color: var(--ui-gray);
  font-size: 28px;
  opacity: 0.5;
  border: none;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab-top-left:hover { opacity: 0.8; }

/* Recognition Bar */
.recognition-bar {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ui-bg);
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 200;
  box-shadow: 3px 4px 0 rgba(0,0,0,0.1);
  max-width: 90vw;
}

.recognition-bar.hidden { display: none; }

#recognized-text {
  font-family: var(--font-hand);
  font-size: 16px;
  color: var(--ui-gray);
  white-space: nowrap;
}

#equation-input {
  font-family: var(--font-hand);
  font-size: 22px;
  font-weight: 600;
  border: none;
  border-bottom: 2px solid var(--ui-light);
  background: transparent;
  color: var(--ink);
  outline: none;
  width: 220px;
  padding: 4px 2px;
}

.confirm-btn {
  font-family: var(--font-hand);
  font-size: 18px;
  font-weight: 700;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 12px;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
}

.cancel-btn {
  font-family: var(--font-hand);
  font-size: 20px;
  background: transparent;
  color: var(--ui-gray);
  border: none;
  cursor: pointer;
  padding: 4px 8px;
}

/* Panels */
.panel {
  position: fixed;
  top: 0;
  width: 300px;
  height: 100%;
  background: var(--ui-bg);
  z-index: 300;
  padding: 24px;
  overflow-y: auto;
  border: none;
  box-shadow: 4px 0 16px rgba(0,0,0,0.1);
  transition: transform 0.2s ease;
}

.panel.hidden {
  display: none;
}

.panel-right {
  right: 0;
  border-left: 2px solid var(--ink);
}

.panel-left {
  left: 0;
  border-right: 2px solid var(--ink);
  box-shadow: 4px 0 16px rgba(0,0,0,0.1);
}

.panel-title {
  font-family: var(--font-hand);
  font-size: 32px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 24px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 8px;
}

.setting-group {
  margin-bottom: 20px;
}

.setting-group label {
  display: block;
  font-family: var(--font-hand);
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 8px;
}

.btn-group {
  display: flex;
  gap: 8px;
}

.stroke-btn, .grid-btn {
  font-family: var(--font-hand);
  font-size: 17px;
  padding: 8px 14px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.1s;
}

.stroke-btn.active, .grid-btn.active {
  background: var(--ink);
  color: var(--paper);
}

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

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

.toggle-label {
  font-size: 17px !important;
  font-weight: 400 !important;
  color: var(--ui-gray) !important;
}

.clear-all-btn {
  font-family: var(--font-hand);
  font-size: 18px;
  font-weight: 600;
  width: 100%;
  padding: 12px;
  border: 2px solid #c44;
  border-radius: 12px;
  background: transparent;
  color: #c44;
  cursor: pointer;
  margin-top: 20px;
}

.clear-all-btn:active {
  background: #c44;
  color: white;
}

/* History */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  padding: 12px;
  border: 1.5px solid var(--ui-light);
  border-radius: 10px;
  cursor: pointer;
}

.history-item:hover {
  border-color: var(--ink);
}

.history-eq {
  font-family: var(--font-hand);
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
}

.history-ans {
  font-family: var(--font-hand);
  font-size: 24px;
  font-weight: 700;
  color: var(--answer-ink);
}

.history-time {
  font-family: var(--font-hand);
  font-size: 14px;
  color: var(--ui-gray);
}

/* Footer */
.footer {
  position: fixed;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-hand);
  font-size: 13px;
  color: rgba(0,0,0,0.18);
  white-space: nowrap;
  pointer-events: auto;
  z-index: 10;
}

.footer a {
  color: rgba(0,0,0,0.25);
  text-decoration: none;
}

.footer a:hover {
  color: rgba(0,0,0,0.45);
}

/* Overlay for closing panels */
#panel-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 250;
  background: rgba(0,0,0,0.08);
  display: none;
}

#panel-overlay.active {
  display: block;
}