/* ===========================
   Modern Responsive Theme
   =========================== */

/* Farbvariablen: Light Theme */
:root {
--primary: #2563EB;
--primary-light: #E0E7FF;
--accent: #F59E42;
--bg: #F9FAFB;
--surface: #FFFFFF;
--surface-rgba: rgba(255, 255, 255, 0.7);
--border: #E5E7EB;
--text: #1F2937;
--text-light: #4B5563;
--shadow: 0 2px 8px rgba(31, 41, 55, 0.08);
--radius: 16px;
--spacing-1: 0.5rem;
--spacing-2: 1rem;
--spacing-3: 1.5rem;
--transition: 0.2s cubic-bezier(.4,0,.2,1);
}

/* Dark Theme */
[data-theme="dark"] {
--primary: #60A5FA;
--primary-light: #1E293B;
--accent: #FBBF24;
--bg: #0F172A;
--surface: #1E293B;
--surface-rgba: rgba(30, 41, 59, 0.7);
--border: #334155;
--text: #F1F5F9;
--text-light: #CBD5E1;
--shadow: 0 2px 12px rgba(0, 0, 0, 0.20);
}

/* ========== Base & Layout ========== */
html {
  box-sizing: border-box;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: contain;
}
*, *::before, *::after { box-sizing: inherit; }

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: system-ui, 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: contain;
}

main {
  margin: 0 auto;
  padding: var(--spacing-2);
  max-width: 900px;
  width: 100%;
}

/* ========== Headers ========== */
.dashboard-header, header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--spacing-2);
    background: var(--surface-rgba);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.dashboard-header > div, header > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 900px;
}

.header-actions { display: flex; gap: var(--spacing-1); }

/* Shrinking Header on view.php */
header {
    transition: padding 0.3s ease;
}
header nav, header .display {
    transition: all 0.3s ease;
    max-height: 100px; /* Set an explicit height to transition from */
    overflow: hidden;
}
header.is-shrunk {
    padding-top: var(--spacing-1);
    padding-bottom: var(--spacing-1);
}
header.is-shrunk nav, header.is-shrunk .display {
    opacity: 0;
    max-height: 0;
    margin: 0;
    padding: 0;
    pointer-events: none;
}
header.is-shrunk #current-class-display {
    font-weight: 600;
}


/* ========== Buttons ========== */
.button, .arrow-button, .dark-button, #go-to-settings-button, .theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  outline: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 500;
  padding: 0.65em 1.2em;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  min-height: 44px;
}

#go-to-settings-button { background: var(--accent); width: 44px; padding: 0; }

/* ========== Dashboard ========== */
.favorites-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-2);
    padding: var(--spacing-2);
    max-width: 900px;
    margin: 0 auto;
}

.favorite-card {
    aspect-ratio: 4 / 3;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: var(--spacing-1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.favorite-card h3 { color: var(--primary); font-size: 2rem; margin: 0; }
.favorite-card p { color: var(--text-light); margin: 0; font-size: 0.9rem; }

.favorite-card.placeholder {
    border: 2px dashed var(--border);
    background: var(--primary-light);
}
.favorite-card.placeholder h3 { font-size: 2.5rem; color: var(--border); }

/* Edit Mode */
@keyframes jiggle {
    from { transform: rotate(-1.5deg); }
    to { transform: rotate(1.5deg); }
}

body.edit-mode-active .favorite-card {
    animation: jiggle 0.2s infinite alternate;
}

body.edit-mode-active .favorite-card:not(.placeholder) {
    filter: grayscale(80%);
    opacity: 0.7;
}


/* ========== Modal Styles ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.modal-overlay.visible { opacity: 1; pointer-events: auto; }
.modal-content {
    background: var(--surface-rgba);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    transition: transform 0.3s ease;
}
.modal-overlay.visible .modal-content { transform: scale(1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: var(--spacing-2); border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; color: var(--primary); }
.close-button { background: none; border: none; font-size: 2rem; color: var(--text-light); cursor: pointer; }
.modal-body { padding: var(--spacing-2); overflow-y: auto; }
#class-selection-list { display: flex; flex-direction: column; gap: 0.5rem; }
.class-item { background: var(--primary-light); color: var(--primary); border-radius: calc(var(--radius) / 2); padding: 0.8rem 1rem; cursor: pointer; text-align: center; font-weight: 500; }

/* ========== Table Styles ========== */
@keyframes fade-slide-in-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  overflow: hidden;
  /* Animation for view.php */
  animation: fade-slide-in-up 0.5s var(--transition);
}

th, td {
  padding: 0.85em 0.5em;
  text-align: center;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

th {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  border-bottom: 2px solid var(--primary);
}

tr:last-child td { border-bottom: none; }

/* ========== Flip Card Fullscreen Animation ========== */

/* This container will hold the card that is being animated to fullscreen */
.fullscreen-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    pointer-events: none; /* Pass clicks through unless a card is active */
    perspective: 1500px;
}

/* The card itself, which is a child of .favorites-grid initially */
.flip-card {
    width: 100%;
    height: 100%;
    perspective: 1500px;
    position: relative;
}

.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.7s ease-in-out;
    transform-style: preserve-3d;
}

/* When the card is active/flipped */
.flip-card.is-active .flip-card-inner {
    transform: rotateX(180deg);
}

.flip-card-front, .flip-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden; /* Safari */
    backface-visibility: hidden;
    border-radius: var(--radius);
    overflow: hidden; /* Ensures content doesn't spill out */
    transition: border-radius 0.3s ease-in-out 0.4s; /* Match parent radius animation */
}

.fullscreen-container .favorite-card.is-fullscreen .flip-card-front,
.fullscreen-container .favorite-card.is-fullscreen .flip-card-back {
    border-radius: 0px;
}

.flip-card-front {
    /* This is the original .favorite-card styling */
    background: var(--surface);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text);
    cursor: pointer;
}

.flip-card-front.placeholder {
    border: 2px dashed var(--border);
    background: var(--primary-light);
}
.flip-card-front.placeholder h3 {
    font-size: 2.5rem;
    color: var(--border);
}

.flip-card-back {
    background-color: var(--bg); /* Background color while iframe loads */
    color: white;
    transform: rotateX(180deg);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.iframe-scaler {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    transform-origin: top left;
}

.flip-card-back iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: var(--bg);
}

/* Fullscreen state */
.fullscreen-container.active {
    pointer-events: all; /* Capture clicks when active */
}

.fullscreen-container .favorite-card {
    /* This is now the main animation target */
    position: absolute;
    transition: transform 0.7s ease-in-out, border-radius 0.3s ease-in-out 0.4s;
    will-change: transform;
}

#native-fullscreen-iframe-container {
    position: fixed;
    inset: 0;
    z-index: 200; /* On top of the animation container */
    visibility: hidden;
    background: var(--bg);
}

#native-fullscreen-iframe-container.visible {
    visibility: visible;
}

#native-fullscreen-iframe-container iframe {
    width: 100%;
    height: 100%;
    border: none;
}

