*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0f14;
  --surface: #1a1d27;
  --surface2: #252836;
  --border: #2e3147;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #3b82f6;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

.light-mode {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #1d4ed8;
  --text: #0f172a;
  --text-muted: #64748b;
  --shadow: 0 4px 24px rgba(0,0,0,0.1);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

a { color: var(--accent-light); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  border: none;
  outline: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

input, textarea, select {
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
  user-select: text;
  -webkit-user-select: text;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 1rem;
  transition: background 0.15s, transform 0.1s;
  min-height: 48px;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1.5px solid var(--border); }
.btn-ghost:hover { border-color: var(--accent); color: var(--text); }
.btn-full { width: 100%; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 16px;
}
.alert-error { background: rgba(220,38,38,0.15); border: 1px solid rgba(220,38,38,0.3); color: #fca5a5; }
.alert-success { background: rgba(22,163,74,0.15); border: 1px solid rgba(22,163,74,0.3); color: #86efac; }

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.page-header h1 { font-size: 1.2rem; font-weight: 700; flex: 1; text-align: center; }
.back-btn {
  background: none;
  color: var(--text);
  font-size: 1.5rem;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}
.back-btn:hover { background: var(--surface2); }

/* Toggle switch Nei/Ja */
.toggle-group {
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 6px;
}
.toggle-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}
.toggle-btn-group {
  display: flex;
  background: #111;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.toggle-btn-group button {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  background: transparent;
  color: var(--text-muted);
  min-width: 50px;
  min-height: 36px;
  transition: background 0.15s, color 0.15s;
}
.toggle-btn-group button.active {
  background: var(--surface);
  color: var(--text);
}

/* Drawing toolbar */
.draw-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.draw-tool-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  color: var(--text);
  font-size: 1.1rem;
  transition: background 0.15s;
  border: 1.5px solid transparent;
}
.draw-tool-btn.active { border-color: var(--accent); background: rgba(37,99,235,0.2); }
.draw-tool-btn:hover { background: var(--border); }
.color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  cursor: pointer;
  transition: transform 0.1s;
}
.color-dot.active { border-color: #fff; transform: scale(1.2); }
.draw-sep { width: 1px; height: 28px; background: var(--border); margin: 0 4px; }

/* Canvas overlay */
.canvas-container {
  position: relative;
  flex: 1;
  overflow: hidden;
}
.draw-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  cursor: crosshair;
  z-index: 10;
}
.draw-canvas.active { pointer-events: all; }

/* Responsive */
@media (max-width: 600px) {
  .card { padding: 16px; }
  .page-header h1 { font-size: 1rem; }
}
