* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #F5F0E8;
  touch-action: none;
  overscroll-behavior: none;
  font-family: 'Caveat', 'Kalam', cursive;
}

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

#recognition-preview {
  position: fixed;
  bottom: 60px;
  left: 16px;
  right: 80px;
  font-family: 'Kalam', cursive;
  font-size: 20px;
  color: #AAA;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 2px;
  height: 28px;
  line-height: 28px;
}

#toolbar {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 8px;
  z-index: 100;
}

#toolbar button {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid #CCC;
  background: rgba(245, 240, 232, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
}

#toolbar button:active {
  transform: scale(0.9);
}

#toolbar-buttons {
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  transition: opacity 0.2s;
}

#toolbar-buttons.hidden {
  display: none;
}

#toolbar.faded {
  opacity: 0.2;
}

#toolbar.faded:hover,
#toolbar.faded:active {
  opacity: 1;
}

#history-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(340px, 80vw);
  height: 100%;
  background: #F5F0E8;
  border-left: 2px solid #CCC;
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.3s ease;
}

#history-panel.hidden {
  transform: translateX(100%);
  pointer-events: none;
}

#history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 2px solid #CCC;
  font-family: 'Caveat', cursive;
  font-size: 28px;
  font-weight: 700;
  color: #333;
}

#history-header button {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #666;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
}

.history-item {
  padding: 12px 0;
  border-bottom: 1px solid #E0D8CC;
  font-family: 'Caveat', cursive;
  font-size: 26px;
  color: #333;
  line-height: 1.4;
}

.history-item .eq {
  color: #666;
}

.history-item .res {
  color: #000;
  font-weight: 700;
  margin-left: 4px;
}

.history-item .ts {
  display: block;
  font-size: 16px;
  color: #AAA;
  font-family: 'Kalam', cursive;
}

#history-footer {
  padding: 12px 20px;
  border-top: 1px solid #E0D8CC;
  text-align: center;
}

#history-footer a {
  font-family: 'Caveat', cursive;
  font-size: 18px;
  color: #BBB;
  text-decoration: none;
}

#history-footer a:hover {
  color: #888;
}

#answer-overlay {
  position: fixed;
  pointer-events: none;
  z-index: 50;
  font-family: 'Caveat', cursive;
  font-weight: 700;
  color: #000;
}

.answer-char {
  display: inline-block;
  opacity: 0;
  animation: writeIn 0.15s ease forwards;
}

@keyframes writeIn {
  0% { opacity: 0; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}

.error-shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

@keyframes fadeOutCanvas {
  0% { opacity: 1; }
  100% { opacity: 0; }
}