:root {
  --bg: #f7f4f1;
  --surface: #ffffff;
  --border: #e9e2d9;
  --text: #241811;
  --text-muted: #79705f;
  --text-faint: #a99e8d;

  --coffee-dark: #3d2418;
  --coffee: #6f4e37;
  --tan: #c9946a;
  --tan-soft: #f3e4d5;

  --danger: #b3492c;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;

  --shadow-sm: 0 1px 2px rgba(36, 24, 18, 0.06);
  --shadow-md: 0 8px 24px rgba(36, 24, 18, 0.10);

  color-scheme: light;
}

* { box-sizing: border-box; }

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

button, input {
  font-family: inherit;
}

h2, h3 {
  letter-spacing: -0.01em;
}

.screen {
  height: 100dvh;
  overflow: hidden;
  flex-direction: column;
}

.screen[hidden] { display: none; }
.screen:not([hidden]) { display: flex; }

/* Onboarding */
#onboarding {
  align-items: center;
  justify-content: center;
  background: var(--coffee-dark);
  padding: 24px;
}

.onboarding-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 36px 28px 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.brand-logo {
  width: 108px;
  height: 108px;
  border-radius: 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.onboarding-question {
  margin: 0 0 4px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.onboarding-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0 14px;
}

.onboarding-buttons button {
  padding: 14px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--coffee-dark);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.onboarding-buttons button:active { transform: scale(0.98); opacity: 0.92; }

.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 6px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* App shell */
.app-header {
  background: var(--coffee-dark);
  color: var(--bg);
  padding: 12px 16px calc(10px + env(safe-area-inset-top, 0px));
  padding-top: max(12px, env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.scoreboard {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.score-side {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.score-name {
  font-size: 0.78rem;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90px;
}

.score-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--tan);
}

.score-mid {
  font-size: 0.75rem;
  opacity: 0.75;
}

.whoami-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: var(--bg);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.view {
  flex: 1;
  padding: 20px 16px 92px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.today-date {
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.upload-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}

#upload-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.source-buttons {
  display: flex;
  gap: 10px;
}

.file-picker {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 18px 8px;
  text-align: center;
  color: var(--coffee);
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.file-picker:hover { border-color: var(--coffee); }

.file-picker-icon {
  width: 24px;
  height: 24px;
  color: var(--text-faint);
}

.file-picker input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.photo-preview-wrap {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg);
}

.photo-preview-wrap img {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  display: block;
}

.photo-preview-wrap .link-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(36, 24, 18, 0.6);
  color: white;
  border-radius: 999px;
  padding: 5px 12px;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
}

#caption-input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
}

#caption-input:focus, .settings-card input:focus {
  outline: none;
  border-color: var(--coffee);
}

.primary-btn {
  background: var(--coffee-dark);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.primary-btn:disabled { opacity: 0.55; }
.primary-btn:not(:disabled):active { opacity: 0.85; }

.hint {
  font-size: 0.78rem;
  color: var(--text-faint);
  margin: 8px 2px 0;
  min-height: 1em;
}

.today-status {
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 14px;
  min-height: 1.2em;
}

.section-empty {
  font-size: 0.82rem;
  color: var(--text-faint);
  margin: 0;
}

.feed {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.feed-post {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.feed-post-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}

.avatar {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
}

.avatar-a { background: var(--coffee-dark); }
.avatar-b { background: var(--tan); }

.feed-post-headtext {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}

.feed-post-name {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text);
}

.feed-post-time {
  font-size: 0.72rem;
  color: var(--text-faint);
}

.photo-media {
  position: relative;
}

.photo-media img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  cursor: pointer;
  background: var(--bg);
}

.feed-post-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px 0;
}

.feed-post-votehint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.feed-caption {
  margin: 8px 14px 0;
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.4;
}

.feed-caption strong {
  margin-right: 5px;
}

.feed-comments {
  margin: 8px 14px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.feed-comment {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.4;
}

.feed-comment strong {
  margin-right: 5px;
}

.feed-comment-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  margin-top: 6px;
  border-top: 1px solid var(--border);
}

.feed-comment-form input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.85rem;
}

.feed-comment-form input:focus {
  outline: none;
  border-color: var(--coffee);
}

.feed-comment-form button {
  border: none;
  background: none;
  color: var(--coffee-dark);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 6px;
  flex-shrink: 0;
}

.star-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(36, 24, 18, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: background 0.15s ease;
}

.star-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: white;
  stroke-width: 1.8;
  stroke-linejoin: round;
}

.star-btn.voted {
  background: rgba(36, 24, 18, 0.55);
}

.star-btn.voted svg {
  fill: var(--tan);
  stroke: var(--tan);
}

.vote-count {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--coffee-dark);
  background: var(--tan-soft);
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.winner-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--tan);
  color: var(--coffee-dark);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

/* Calendar */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.calendar-nav h2 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  color: var(--text);
  cursor: pointer;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-faint);
  margin-bottom: 6px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.cal-day {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-size: 0.78rem;
  color: var(--text);
  overflow: hidden;
  cursor: default;
}

.cal-day.empty-slot { background: transparent; border-color: transparent; }

.cal-day img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.cal-day.has-winner::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 55%;
  background: linear-gradient(to top, rgba(20, 12, 8, 0.75), transparent);
  z-index: 1;
}

.cal-day .cal-daynum {
  position: relative;
  z-index: 2;
}

.cal-day.has-winner .cal-daynum {
  position: absolute;
  bottom: 3px;
  right: 5px;
  color: white;
  font-weight: 700;
  font-size: 0.72rem;
}

.cal-day.pending { border-color: var(--tan); border-style: dashed; }
.cal-day.tie { border-color: var(--text-faint); border-style: dashed; }
.cal-day.clickable { cursor: pointer; }
.cal-day.person-a { box-shadow: inset 0 0 0 2px var(--coffee-dark); }
.cal-day.person-b { box-shadow: inset 0 0 0 2px var(--tan); }

/* Score view */
.score-big-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 16px 22px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.score-big-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.score-big-name {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.score-big-value {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--coffee-dark);
  letter-spacing: -0.02em;
}

.score-big-vs {
  font-size: 1.2rem;
  color: var(--text-faint);
}

.score-big-meta {
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.settings-card h3 {
  margin: 0 0 14px;
  font-size: 0.95rem;
}

.settings-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.settings-card input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 0.95rem;
  color: var(--text);
}

/* Tabbar */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 10px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-faint);
  cursor: pointer;
}

.tab-btn svg {
  width: 22px;
  height: 22px;
}

.tab-btn span { font-size: 0.68rem; font-weight: 600; }

.tab-btn.active { color: var(--coffee-dark); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal[hidden] { display: none; }
.modal:not([hidden]) { display: flex; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 16, 11, 0.55);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(36, 24, 18, 0.55);
  color: white;
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 0.95rem;
  cursor: pointer;
  z-index: 1;
}

.modal-content img {
  width: 100%;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  background: var(--bg);
}

.modal-photo-block {
  margin-bottom: 16px;
}

.modal-photo-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--coffee-dark);
  font-weight: 600;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--coffee-dark);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

@media (min-width: 560px) {
  .screen { max-width: 480px; margin: 0 auto; box-shadow: var(--shadow-md); }
  body { background: var(--coffee-dark); }
}
