* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: #1a1a2e;
  color: #eee;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #16213e;
  border-bottom: 1px solid #0f3460;
  flex-shrink: 0;
  flex-wrap: wrap;
  z-index: 10;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-group + .toolbar-group {
  border-left: 1px solid #0f3460;
  padding-left: 10px;
}

.tool-btn {
  background: #0f3460;
  border: 1px solid #1a4a8a;
  color: #ccc;
  padding: 6px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.tool-btn:hover {
  background: #1a4a8a;
  color: #fff;
}

.tool-btn.active {
  background: #e94560;
  border-color: #e94560;
  color: #fff;
}

.tool-btn.danger {
  color: #e94560;
}

.tool-btn.danger:hover {
  background: #e94560;
  color: #fff;
}

.tool-label {
  font-size: 12px;
  color: #aaa;
  white-space: nowrap;
}

#color-picker {
  width: 36px;
  height: 30px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: none;
  padding: 0;
}

#color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

#color-picker::-webkit-color-swatch {
  border: 1px solid #1a4a8a;
  border-radius: 4px;
}

#size-slider {
  width: 100px;
  accent-color: #e94560;
  cursor: pointer;
}

#size-label {
  min-width: 55px;
}

.undo-redo-group {
  /* Remove left border to keep undo/redo visually closer to tools */
}

.undo-redo-group + .toolbar-group {
  border-left: 1px solid #0f3460;
  padding-left: 10px;
}

.tool-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.zoom-info {
  margin-left: auto;
}

#zoom-level {
  font-size: 13px;
  color: #888;
  font-variant-numeric: tabular-nums;
}

/* Canvas container */
#canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #2d2d44;
  cursor: crosshair;
}

#canvas-container.panning {
  cursor: grab;
}

#canvas-container.panning:active {
  cursor: grabbing;
}

#draw-canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
}

/* Countdown */
#countdown {
  position: fixed;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: none;
  z-index: 5;
}

#countdown-value {
  font-size: 36px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #e94560;
  text-shadow: 0 0 20px rgba(233, 69, 96, 0.4), 0 2px 8px rgba(0, 0, 0, 0.6);
  letter-spacing: 4px;
}

#countdown-label {
  font-size: 12px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 2px;
}

/* Info overlay */
#info-overlay {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 52, 96, 0.85);
  color: #888;
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 20px;
  pointer-events: none;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  text-align: center;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

#info-overlay kbd {
  background: #1a4a8a;
  color: #eee;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-family: inherit;
}

/* Desktop hints: show by default */
.hint-desktop { display: inline; }
.hint-touch { display: none; }

/* Touch devices: hide desktop hints, show touch hints */
@media (hover: none) and (pointer: coarse) {
  .hint-desktop { display: none; }
  .hint-touch { display: inline; }
  #info-overlay {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    max-width: 85vw;
    line-height: 1.4;
  }
}

/* Narrow screens: wrap text for readability */
@media (max-width: 500px) {
  #info-overlay {
    font-size: 10px;
    padding: 4px 10px;
    white-space: normal;
    line-height: 1.3;
    max-width: 92vw;
  }
}

/* Touch text input popup */
.text-input-popup {
  position: fixed;
  z-index: 100;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.text-input-popup input {
  background: #0f3460;
  border: 1px solid #1a4a8a;
  color: #eee;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 14px;
  outline: none;
  min-width: 200px;
}

.text-input-popup input:focus {
  border-color: #e94560;
}

.text-input-popup .popup-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.text-input-popup button {
  background: #0f3460;
  border: 1px solid #1a4a8a;
  color: #eee;
  padding: 5px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.text-input-popup button:hover {
  background: #1a4a8a;
}

.text-input-popup button.primary {
  background: #e94560;
  border-color: #e94560;
}

.text-input-popup button.primary:hover {
  background: #ff5a7a;
}

/* Responsive adjustments */
@media (max-width: 700px) {
  #toolbar {
    padding: 6px 8px;
    gap: 6px;
  }

  #size-slider {
    width: 70px;
  }

  #info-overlay {
    font-size: 10px;
    padding: 4px 10px;
  }
}
