:root {
  --bg: radial-gradient(circle at 20% 20%, #fdf6ff 0%, #eef2ff 45%, #e8f4fd 100%);
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --ink: #212529;
  --muted: #495057;
  --line: #ced4da;
  --accent: #0f766e;
  --danger: #ff0000;
  --warn: #ffd400;
  --ok: #00a000;
  --great: #0066ff;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  font-family: "Nunito", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

.app-shell {
  width: min(980px, 100% - 1rem);
  height: 100vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 0.6rem 0 0.35rem;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  min-height: 48px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2.1rem);
  letter-spacing: 0.02em;
  text-align: center;
  background: linear-gradient(135deg, #0f766e 0%, #3b82f6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 800;
}

#logoutButton {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
}

.hidden {
  display: none !important;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
}

#learnView {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
  padding-bottom: 72px;
}

#loginView {
  margin: auto;
  width: min(430px, 100%);
  display: grid;
  gap: 0.8rem;
}

#loginView h2 {
  margin: 0;
  text-align: center;
}

form {
  display: grid;
  gap: 0.6rem;
}

input,
button {
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 0.7rem 0.8rem;
  font-size: 1rem;
}

button {
  cursor: pointer;
  background: var(--surface-2);
  transition: transform 150ms ease, box-shadow 150ms ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

button:active {
  transform: scale(0.95);
  box-shadow: none;
}

.ghost {
  background: transparent;
}

.status-row {
  margin: 0.3rem 0 0.6rem;
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  color: var(--muted);
}

.card-stage {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex: 1;
  min-height: 0;
}

@keyframes bounce-in {
  0%   { transform: scale(0) rotate(-10deg); opacity: 0; }
  60%  { transform: scale(1.3) rotate(6deg);  opacity: 1; }
  80%  { transform: scale(0.9) rotate(-3deg); }
  100% { transform: scale(1)   rotate(0deg); }
}

.celebrate-emoji {
  font-size: 3.5rem;
  line-height: 1;
  animation: bounce-in 0.55s ease both;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.toast {
  position: fixed;
  bottom: 5.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1e2a3a;
  color: #fff;
  padding: 0.65rem 1.4rem;
  border-radius: 99px;
  font-size: 0.95rem;
  z-index: 100;
  animation: toast-in 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
}

#emptyState {
  margin: auto;
  max-width: 620px;
  min-height: 240px;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 0.8rem;
  background: linear-gradient(145deg, #f8fff9, #eefcf7 45%, #ebf8ff);
}

#emptyState h2 {
  margin: 0;
  font-size: clamp(1.5rem, 2.7vw, 2rem);
}

#emptyState p {
  margin: 0;
  color: #31514c;
}

#emptyState button {
  justify-self: center;
}

.flip-card {
  --swipe-left-opacity: 0;
  --swipe-right-opacity: 0;
  position: relative;
  min-height: 0;
  flex: 1;
  perspective: 1000px;
  cursor: pointer;
  overflow: hidden;
  touch-action: pan-y;
  transition: transform 180ms ease, box-shadow 200ms ease;
}

.flip-card:not(.swiping):hover {
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.13);
}

.flip-card::before,
.flip-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  transition: opacity 120ms ease;
}

.flip-card::before {
  opacity: var(--swipe-left-opacity);
  background: linear-gradient(90deg, rgba(255, 24, 24, 0.74), rgba(255, 24, 24, 0));
}

.flip-card::after {
  opacity: var(--swipe-right-opacity);
  background: linear-gradient(270deg, rgba(0, 112, 255, 0.74), rgba(0, 112, 255, 0));
}

.flip-card.swiping {
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.16);
}

.flip-card.swiping {
  transition: none;
}

.flip-inner {
  position: relative;
  min-height: 100%;
  width: 100%;
  transition: transform 450ms ease;
  transform-style: preserve-3d;
}

.flip-card.flipped .flip-inner {
  transform: rotateY(180deg);
}

.flip-card.no-flip-transition .flip-inner {
  transition: none;
}

.face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 1.2rem;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 1rem;
  overflow: hidden;
}

.face.front {
  justify-content: center;
}

.face.back {
  transform: rotateY(180deg);
}

.card-text {
  width: 100%;
}

.card-text.large-centered {
  font-size: clamp(1.3rem, 2.7vw, 2rem);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.card-text.multiline {
  font-size: 1rem;
  line-height: 1.55;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.card-image {
  width: 100%;
  max-height: min(34vh, 280px);
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.rating-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(env(safe-area-inset-bottom), 0px);
  z-index: 20;
  width: min(980px, 100% - 1rem);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  padding: 0.35rem 0.2rem 0.35rem;
}

.rating-bar button {
  color: #fff;
  border: none;
  white-space: nowrap;
  font-weight: 700;
  padding: 1.05rem 0.3rem;
}

.rating-bar .danger { background: var(--danger); }
.rating-bar .warn { background: var(--warn); }
.rating-bar .ok { background: var(--ok); }
.rating-bar .great { background: var(--great); }

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw, 100% - 0.5rem);
    padding-top: 0.3rem;
  }

  .flip-card,
  .flip-inner {
    min-height: 100%;
  }

  .rating-bar {
    width: min(100vw, 100% - 0.5rem);
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.35rem;
  }

  .rating-bar button {
    font-size: 0.9rem;
    padding: 0.95rem 0.2rem;
  }
}

@media screen and (orientation: landscape) and (hover: none) {
  html {
    transform: rotate(-90deg) translateX(-100%);
    transform-origin: 0 0;
    width: 100vh;
    height: 100vw;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
  }
}
