:root {
  --bg: #0b0b0f;
  --bg-elevated: #14141c;
  --bg-card: #1a1a24;
  --bg-input: #101018;
  --line: #2a2a36;
  --text: #f5f5f7;
  --muted: #9a9aaa;
  --yellow: #fffc00;
  --yellow-dim: #c4c200;
  --green: #3dd68c;
  --red: #ff5d73;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --nav-h: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

body:not(.authed) {
  padding-bottom: var(--safe-bottom);
}

body:not(.authed) .nav,
body:not(.authed) .logout-btn {
  display: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 10px;
  background: linear-gradient(180deg, #0b0b0f 70%, rgba(11, 11, 15, 0.75) 100%);
}

.app-header img {
  width: 36px;
  height: 36px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.app-header p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.logout-btn {
  margin-left: auto;
  width: auto;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  cursor: pointer;
  font-weight: 600;
}

main {
  padding: 8px 16px 24px;
  max-width: 720px;
  margin: 0 auto;
}

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #12121a;
  border-top: 1px solid var(--line);
}

.nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.72rem;
  min-height: 44px;
}

.nav a.active {
  color: var(--yellow);
}

.nav svg {
  width: 22px;
  height: 22px;
}

.hidden {
  display: none !important;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card-link {
  display: block;
  text-decoration: none;
}

.card-link:active,
.btn:active {
  transform: scale(0.99);
}

.profile-card h2,
.section-title {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.username {
  color: var(--muted);
  font-size: 0.85rem;
}

.score {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  margin: 10px 0 12px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric {
  background: var(--bg-elevated);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  margin-bottom: 4px;
}

.metric strong {
  font-size: 0.95rem;
}

.delta-pos {
  color: var(--green);
}

.delta-zero {
  color: var(--muted);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}

.empty h2 {
  color: var(--text);
  margin-bottom: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 16px;
  border: 0;
  border-radius: 14px;
  background: var(--yellow);
  color: #111;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  width: 100%;
}

.btn.secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn.danger {
  background: #3a1520;
  color: #ffb4bf;
  border: 1px solid #5a2230;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--bg-elevated);
  padding: 6px;
  border-radius: 16px;
  margin-bottom: 14px;
}

.segmented button {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
}

.segmented button.active {
  background: var(--yellow);
  color: #111;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 12px 0 6px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg-input);
  padding: 12px 14px;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--yellow);
  border-color: var(--yellow);
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.list-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.list-item .meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #111;
  background: var(--yellow-dim);
  border-radius: 999px;
  padding: 3px 8px;
  font-weight: 700;
}

.scanner {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 3 / 4;
  margin-bottom: 12px;
}

.scanner video,
.scanner img,
.scanner canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scanner canvas.preview {
  object-fit: contain;
  background: #000;
}

.profile-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.profile-mask-svg {
  width: 100%;
  height: 100%;
}

.profile-mask .mask-dim {
  fill: rgba(0, 0, 0, 0.42);
}

.profile-mask .mask-cut {
  fill: #000;
}

.profile-mask .mask-line {
  fill: none;
  stroke: #fffc00;
  stroke-width: 1.1;
}

.profile-mask .mask-line.faint {
  stroke: rgba(255, 255, 255, 0.45);
}

.profile-mask .mask-line.username {
  stroke: #5dff9a;
  fill: rgba(93, 255, 154, 0.08);
}

.profile-mask .mask-line.pills {
  stroke: #fffc00;
  stroke-dasharray: 2 2;
}

.profile-mask .mask-ghost {
  fill: #fffc00;
}

.profile-mask .mask-action {
  fill: none;
  stroke: rgba(255, 255, 255, 0.7);
  stroke-width: 1.1;
}

.profile-mask .mask-label {
  fill: #fffc00;
  font-size: 4px;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 700;
}

.profile-mask .mask-label.user {
  fill: #5dff9a;
}

.ocr-status {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  margin: 8px 0 12px;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  z-index: 40;
  background: #222230;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.toast.error {
  border-color: var(--red);
}

.toast.success {
  border-color: var(--green);
}

.chart-wrap {
  position: relative;
  height: 220px;
}

.profile-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.entry-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.entry-note,
.ai-result {
  white-space: pre-wrap;
  line-height: 1.45;
}

.entry-note {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.ai-result {
  margin-top: 14px;
}

.login-wrap {
  max-width: 420px;
  margin: 24px auto;
}

.select-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.select-row .icon-btn {
  margin-bottom: 0;
}

@media (min-width: 720px) {
  .score {
    font-size: 2.4rem;
  }
}
