:root {
  color-scheme: light;
  --bg: #f6f4f0;
  --card: #ffffff;
  --ink: #2a2621;
  --muted: #7a746a;
  --accent: #e5484d;
  --border: #e6e1d8;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.topbar h1 { font-size: 1.15rem; margin: 0; white-space: nowrap; }

.user-box { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; color: var(--muted); min-width: 0; }
#userEmail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45vw; }
.link-btn {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 0.9rem; padding: 6px 0; text-decoration: underline;
  touch-action: manipulation;
}

.hidden { display: none !important; }

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px calc(60px + env(safe-area-inset-bottom, 0px));
}

.screen { display: block; }

.auth-card {
  max-width: 380px;
  margin: 40px auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
}

.auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab-btn {
  flex: 1; padding: 10px 8px; min-height: 44px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); cursor: pointer; font-size: 0.95rem; touch-action: manipulation;
}
.tab-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.auth-form input, textarea {
  padding: 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 16px;
  min-height: 44px;
}
.auth-form button[type="submit"], .commit-btn {
  padding: 12px; min-height: 46px; border-radius: 8px; border: none; background: var(--accent);
  color: #fff; font-size: 1rem; cursor: pointer; margin-top: 4px; touch-action: manipulation;
  width: 100%;
}
.auth-form button[type="submit"]:hover, .commit-btn:hover { opacity: 0.92; }
.auth-form .link-btn { align-self: flex-start; }

.form-error { color: #c0392b; font-size: 0.85rem; min-height: 1em; margin: 6px 0 0; }
.form-success { color: #2e7d32; font-size: 0.85rem; min-height: 1em; margin: 6px 0 0; }

.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0 12px; color: var(--muted); font-size: 0.8rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

#googleBtn { display: flex; justify-content: center; }
.hint { font-size: 0.75rem; color: var(--muted); text-align: center; margin-top: 8px; }

.wheel-panel {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; text-align: center; margin-bottom: 24px;
}
.wheel-instructions { color: var(--muted); font-size: 0.9rem; margin-top: 0; }

.wheel-wrap { position: relative; max-width: 420px; margin: 0 auto; touch-action: none; }
.wheel-wrap svg { width: 100%; height: auto; display: block; user-select: none; }
.pointer-arrow {
  position: absolute; top: -2px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 16px solid var(--ink);
  pointer-events: none;
}

.selection-readout { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 16px 0; flex-wrap: wrap; }
.chip { background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: 0.9rem; }
.chip-sep { color: var(--muted); }

.intensity-label, .note-label { display: block; text-align: left; font-size: 0.85rem; color: var(--muted); margin: 12px 0; }
.intensity-label input { width: 100%; }
.note-label textarea { width: 100%; margin-top: 6px; resize: vertical; font-family: inherit; }

.history-panel { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 20px; }
.history-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.history-header h2 { margin: 0; font-size: 1rem; }
.export-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.export-buttons button {
  padding: 8px 12px; min-height: 40px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); cursor: pointer; font-size: 0.85rem; touch-action: manipulation;
}

.entry-list { list-style: none; margin: 16px 0 0; padding: 0; max-height: 260px; overflow-y: auto; }
.entry-list li {
  display: flex; justify-content: space-between; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid var(--border); font-size: 0.85rem;
}
.entry-list .entry-emotions { font-weight: 600; }
.entry-list .entry-meta { color: var(--muted); text-align: right; }

.ring-segment { stroke: var(--card); stroke-width: 1; cursor: grab; }
.ring-segment.selected { stroke: var(--ink); stroke-width: 2.5; }
.ring-label { font-size: 11px; pointer-events: none; fill: #2a2621; }

#historyChart { max-width: 100%; }

@media (max-width: 600px) {
  .topbar { padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  .topbar h1 { font-size: 1rem; }
  main { padding: 14px 12px 40px; }
  .auth-card { margin: 20px auto; padding: 18px; }
  .wheel-panel, .history-panel { padding: 14px; border-radius: 12px; }
  .wheel-instructions { font-size: 0.85rem; }
  .selection-readout { gap: 6px; }
  .chip { padding: 6px 10px; font-size: 0.8rem; }
  .history-header { justify-content: flex-start; }
  .export-buttons { width: 100%; }
  .export-buttons button { flex: 1; }
  .entry-list li { flex-direction: column; gap: 2px; }
  .entry-list .entry-meta { text-align: left; }
}

@media (max-width: 480px) {
  .ring-label { font-size: 9.5px; }
}

@media (max-width: 360px) {
  .ring-label { font-size: 8px; }
  .chip { font-size: 0.75rem; padding: 5px 8px; }
}
