@font-face {
  font-family: 'Poppins';
  src: url('../fonts/Poppins-Bold.ttf') format('truetype');
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: 'Poppins';
  src: url('../fonts/Poppins-Medium.ttf') format('truetype');
  font-weight: 500;
  font-display: swap;
}

:root {
  --bg: #1e1f22;
  --card: #2b2d31;
  --card-hi: #35373c;
  --text: #f2f3f5;
  --muted: #b5bac1;
  --gold: #F5C542;
  --accent: #5865F2;
  --gap: 14px;
  --pad: 16px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-weight: 500;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

#app { max-width: 1100px; margin: 0 auto; overflow-x: hidden; }

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
}
button:disabled { cursor: default; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.hdr {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(30, 31, 34, 0.96);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  padding: calc(env(safe-area-inset-top) + 10px) var(--pad) 10px;
  border-bottom: 3px solid var(--accent);
}
.hdr-row { display: flex; align-items: center; gap: 12px; min-height: 0; }
.hdr-row:empty { display: none; }
.back {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  border: 0;
  background: var(--card);
  font-size: 28px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 120ms ease, filter 120ms ease;
}
.back:active { transform: scale(0.92); filter: brightness(1.25); }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.who:empty { display: none; }
.who-text {
  font-size: 18px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.title {
  margin: 6px 0 0;
  font-size: 30px;
  line-height: 1.15;
  font-weight: 700;
}
.ribbon {
  margin-top: 8px;
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--gold);
  color: #1e1f22;
  font-weight: 700;
  font-size: 15px;
  text-align: center;
}

/* ---------- avatars ---------- */
.avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  overflow: hidden;
  background: var(--c, var(--accent));
  flex: 0 0 auto;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar-initial { font-weight: 700; color: #fff; }
.avatar-sm { width: 40px; height: 40px; border: 3px solid var(--c); }
.avatar-sm .avatar-initial { font-size: 18px; }
.avatar-lg { position: absolute; inset: 10%; border: 6px solid var(--c); }
.avatar-lg .avatar-initial { font-size: 56px; }

/* ---------- views ---------- */
.view {
  padding: 16px var(--pad) calc(env(safe-area-inset-bottom) + 28px);
  min-height: 60vh;
}
.anim-fwd { animation: in-fwd 200ms ease-out; }
.anim-back { animation: in-back 200ms ease-out; }
@keyframes in-fwd { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }
@keyframes in-back { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
}
@media (min-width: 600px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 359px) { :root { --gap: 10px; --pad: 12px; } }

/* ---------- tiles ---------- */
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  padding: 10px 10px 12px;
  border: 0;
  border-radius: 22px;
  background: var(--card);
  color: #fff;
  text-align: center;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}
.tile:active { transform: scale(0.95); filter: brightness(1.18); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
.tile:focus-visible { outline: 4px solid var(--accent); outline-offset: 2px; }
.tile:disabled { filter: saturate(0.6) brightness(0.8); }
.tile.saving { filter: none; box-shadow: 0 0 0 4px var(--accent); }

.pic {
  position: relative;
  display: block;
  width: 100%;
  padding-top: 100%;
  border-radius: 16px;
  overflow: hidden;
  background: var(--bg);
}
.pic > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.pic.fallback {
  background: linear-gradient(135deg, var(--c, var(--accent)), #1e1f22 140%);
}
.fallback-letter, .pic-emoji .emoji {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}
.fallback-letter { font-size: 72px; }
.pic-round { background: transparent; }

.label {
  display: block;
  margin-top: 8px;
  font-family: 'Poppins', sans-serif;
  font-weight: 700;
  font-size: 21px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
@media (max-width: 359px) { .label { font-size: 18px; } }

.pill {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%); /* bottom-centre: the art's own gold emblem sits top-right */
  white-space: nowrap;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--gold);
  color: #1e1f22;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.3;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.tile.bonus { box-shadow: 0 0 0 3px var(--gold), 0 4px 0 rgba(0, 0, 0, 0.35); }

.tile.more .pic {
  background: linear-gradient(135deg, var(--accent), #5865F2 60%, #1e1f22 150%);
}
.tile.more .emoji { font-size: 80px; }

.saving-badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-weight: 700;
  font-size: 22px;
  animation: pulse 900ms ease-in-out infinite alternate;
}
@keyframes pulse { from { opacity: 0.75; } to { opacity: 1; } }

/* selected class/activity shown above the clocks */
.chosen {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
}
.chosen span {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--card);
  font-size: 16px;
  font-weight: 700;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.chosen-act { border: 2px solid var(--accent); }

/* ---------- message / done screens ---------- */
.center {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 8px 20px;
}
.logo { font-size: 84px; line-height: 1.1; animation: bob 1.4s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-8px); } }
.big-msg { margin: 16px 0 6px; overflow-wrap: anywhere; font-size: 28px; line-height: 1.2; font-weight: 700; }
.sub-msg { margin: 6px 0; font-size: 20px; line-height: 1.35; color: var(--muted); }
.note { margin: 20px 0 0; text-align: center; color: var(--muted); font-size: 16px; }

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 420px;
  margin-top: 28px;
}
.btn {
  min-height: 60px;
  padding: 12px 20px;
  border-radius: 18px;
  border: 0;
  font-weight: 700;
  font-size: 22px;
  transition: transform 120ms ease, filter 120ms ease;
}
.btn:active { transform: scale(0.95); filter: brightness(1.2); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35); }
.btn-ghost { background: var(--card); color: var(--text); }

.done { padding-top: 24px; }
.check { font-size: 96px; line-height: 1.1; animation: pop 520ms cubic-bezier(0.2, 1.6, 0.4, 1) both; }
@keyframes pop { 0% { transform: scale(0.2); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.xp {
  margin-top: 8px;
  font-size: 56px;
  line-height: 1.1;
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(245, 197, 66, 0.45);
  animation: pop 600ms 120ms cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.done-preview .xp { color: var(--muted); text-shadow: none; font-size: 40px; }
.lines {
  list-style: none;
  margin: 16px 0 0;
  padding: 14px 16px;
  width: 100%;
  max-width: 520px;
  background: var(--card);
  border-radius: 18px;
  text-align: left;
  font-size: 18px;
  line-height: 1.4;
}
.lines li + li { margin-top: 6px; }
.spin {
  margin: 16px 0 0;
  padding: 12px 16px;
  width: 100%;
  max-width: 520px;
  border-radius: 18px;
  background: rgba(245, 197, 66, 0.15);
  border: 2px solid var(--gold);
  font-size: 19px;
  font-weight: 700;
}

.confetti {
  position: absolute;
  top: 70px;
  left: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
}
.confetti i {
  position: absolute;
  left: -5px;
  top: -8px;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  background: var(--c);
  opacity: 0;
  animation: burst 1100ms var(--d, 0ms) cubic-bezier(0.15, 0.7, 0.3, 1) forwards;
}
.confetti i.round { width: 12px; height: 12px; border-radius: 50%; }
@keyframes burst {
  0% { opacity: 1; transform: translate(0, 0) rotate(0) scale(0.6); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--x), calc(var(--y) + 60px)) rotate(var(--r)) scale(1); }
}

/* ---------- toast & overlay ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 14px 20px;
  border-radius: 16px;
  background: #111214;
  border: 2px solid var(--gold);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  text-align: center;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.toast.show { animation: toast-in 200ms ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 16px); } to { opacity: 1; transform: translate(-50%, 0); } }

.closed-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

body.busy .tile:not(.saving) { opacity: 0.7; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
  .confetti { display: none; }
}
