/* ============================================================
   Mana Flashcard — style.css
   ============================================================ */

/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Sora:wght@300;400;500;600;700&family=Noto+Sans+JP:wght@300;400;500;700&display=swap');

/* ── CSS Variables ── */
:root {
  --bg:          #f7f5f0;
  --bg-card:     #ffffff;
  --bg-sidebar:  #1a1a2e;
  --bg-input:    #eeeae3;
  --text:        #1a1717;
  --text-muted:  #6b6560;
  --text-light:  #f7f5f0;
  --border:      #ddd9d0;
  --accent:      #e85d26;
  --accent-dark: #c44a18;
  --accent-2:    #2563eb;
  --success:     #16a34a;
  --warning:     #d97706;
  --danger:      #dc2626;
  --shadow:      0 2px 12px rgba(0,0,0,.08);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.14);
  --radius:      12px;
  --radius-sm:   8px;
  --sidebar-w:   240px;
  --font:        'Sora', 'Noto Sans JP', sans-serif;
  --transition:  .2s cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
  --bg:         #0f0e0d;
  --bg-card:    #1c1b19;
  --bg-sidebar: #111018;
  --bg-input:   #252320;
  --text:       #f0ece6;
  --text-muted: #9a9490;
  --border:     #2e2b27;
  --shadow:     0 2px 12px rgba(0,0,0,.3);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.5);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
  min-height: 100vh;
}
img { max-width: 100%; height: auto; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform var(--transition);
  overflow-y: auto;
}
.sidebar-logo {
  padding: 1.5rem 1.25rem 1rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: #fff;
  display: flex;
  align-items: center;
  gap: .6rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo span.logo-icon {
  background: var(--accent);
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.sidebar-user {
  padding: .85rem 1.25rem;
  font-size: .78rem;
  color: rgba(255,255,255,.45);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-nav { flex: 1; padding: .75rem 0; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .65rem 1.25rem;
  color: rgba(255,255,255,.65);
  font-size: .88rem;
  font-weight: 500;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}
.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255,255,255,.08);
  color: #fff;
}
.sidebar-nav a.active {
  border-left: 3px solid var(--accent);
}
.sidebar-nav .nav-icon { font-size: 1rem; width: 20px; text-align: center; }
.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  gap: .5rem;
  align-items: center;
}
.btn-icon {
  background: none;
  border: none;
  color: rgba(255,255,255,.5);
  cursor: pointer;
  font-size: 1.1rem;
  padding: .35rem;
  border-radius: 6px;
  transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: rgba(255,255,255,.1); color: #fff; }

/* ── Main Content ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: .85rem 1.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 1rem; font-weight: 600; }
.topbar-spacer { flex: 1; }
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.4rem;
  color: var(--text);
  padding: .25rem;
}
.page-body { padding: 1.75rem; flex: 1; }

/* ── Cards / Panels ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.card-sm { padding: 1rem; }

/* ── Deck Grid ── */
.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}
.deck-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
  position: relative;
  overflow: hidden;
}
.deck-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--transition);
}
.deck-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); border-color: var(--accent); }
.deck-card:hover::before { transform: scaleX(1); }
.deck-name { font-weight: 600; font-size: .95rem; margin-bottom: .35rem; }
.deck-meta { font-size: .78rem; color: var(--text-muted); }
.deck-actions {
  display: flex; gap: .4rem;
  margin-top: .9rem;
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  font-family: var(--font);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-success   { background: var(--success); color: #fff; }
.btn-sm        { padding: .35rem .75rem; font-size: .8rem; }
.btn-lg        { padding: .8rem 1.6rem; font-size: 1rem; }
.btn-block     { width: 100%; }

/* ── Form ── */
.form-group { margin-bottom: 1.1rem; }
label { display: block; font-size: .83rem; font-weight: 600; margin-bottom: .4rem; color: var(--text-muted); }
input[type="text"],
input[type="password"],
input[type="file"],
select,
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .65rem .9rem;
  font-family: var(--font);
  font-size: .9rem;
  color: var(--text);
  transition: border-color var(--transition);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }

/* ── Badge ── */
.badge {
  display: inline-flex; align-items: center;
  padding: .2rem .55rem;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
}
.badge-orange  { background: #fff3eb; color: var(--accent); }
.badge-blue    { background: #eff6ff; color: var(--accent-2); }
.badge-green   { background: #f0fdf4; color: var(--success); }
[data-theme="dark"] .badge-orange { background: #3d1a08; }
[data-theme="dark"] .badge-blue   { background: #0d1f3c; }
[data-theme="dark"] .badge-green  { background: #052e16; }

/* ── Stats Row ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: .85rem;
  margin-bottom: 1.5rem;
}
.stat-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  text-align: center;
}
.stat-number { font-size: 1.7rem; font-weight: 700; line-height: 1; }
.stat-label  { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }

/* ──────────────────────────────────────────
   FLASHCARD (Study Page)
   ────────────────────────────────────────── */
.study-container {
  max-width: 680px;
  margin: 0 auto;
}
.study-progress {
  display: flex; align-items: center; gap: .8rem;
  margin-bottom: 1.25rem;
  font-size: .82rem; color: var(--text-muted);
}
.progress-bar {
  flex: 1; height: 6px;
  background: var(--bg-input);
  border-radius: 99px; overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width .4s ease;
}

/* Flip Card */
.flashcard-scene {
  width: 100%; perspective: 1200px;
  margin-bottom: 1.5rem;
  cursor: pointer;
}
.flashcard {
  width: 100%;
  min-height: 260px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .55s cubic-bezier(.4,0,.2,1);
  border-radius: var(--radius);
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  box-shadow: var(--shadow-lg);
  overflow: auto;
  word-break: break-word;
}
.flashcard-face.back {
  transform: rotateY(180deg);
  background: var(--bg-card);
  border-color: var(--accent);
}
.flashcard-text {
  font-size: 1.35rem;
  font-weight: 500;
  text-align: center;
  line-height: 1.5;
}
.flashcard-hint {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: auto;
}
.flashcard-media img { max-height: 140px; border-radius: 8px; }
.flashcard-audio { width: 100%; }

/* Rating Buttons */
.rating-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .6rem;
}
.btn-rate {
  display: flex; flex-direction: column; align-items: center;
  padding: .75rem .5rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
  font-family: var(--font);
}
.btn-rate:hover { transform: translateY(-2px); }
.btn-rate:active { transform: scale(.96); }
.btn-rate .rate-label { font-size: .8rem; font-weight: 700; margin-bottom: .15rem; }
.btn-rate .rate-interval { font-size: .68rem; color: var(--text-muted); }
.btn-rate-1 { border-color: var(--danger);   }  .btn-rate-1:hover  { background: #fef2f2; }
.btn-rate-2 { border-color: var(--warning);  }  .btn-rate-2:hover  { background: #fffbeb; }
.btn-rate-3 { border-color: var(--success);  }  .btn-rate-3:hover  { background: #f0fdf4; }
.btn-rate-4 { border-color: var(--accent-2); }  .btn-rate-4:hover  { background: #eff6ff; }
[data-theme="dark"] .btn-rate-1:hover { background: #2d0a0a; }
[data-theme="dark"] .btn-rate-2:hover { background: #2d1e0a; }
[data-theme="dark"] .btn-rate-3:hover { background: #052e16; }
[data-theme="dark"] .btn-rate-4:hover { background: #0d1f3c; }

/* ── Multi-deck Selector ── */
.deck-checkboxes { display: flex; flex-direction: column; gap: .5rem; margin: .75rem 0; }
.deck-check-item {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .85rem;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color var(--transition);
}
.deck-check-item:hover { border-color: var(--accent); }
.deck-check-item input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

/* ── Import ── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  transition: border-color var(--transition), background var(--transition);
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--accent); background: rgba(232,93,38,.04); }
.drop-zone-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.drop-zone input[type="file"] { display: none; }
.import-progress { margin-top: 1rem; display: none; }
.import-log {
  margin-top: 1rem;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  font-size: .8rem;
  font-family: monospace;
  max-height: 180px;
  overflow-y: auto;
  display: none;
}
.log-ok    { color: var(--success); }
.log-error { color: var(--danger); }
.log-info  { color: var(--text-muted); }

/* ── Login Page ── */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 1rem;
}
.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  display: flex; align-items: center; gap: .6rem;
  font-size: 1.3rem; font-weight: 700;
  margin-bottom: 1.75rem;
  justify-content: center;
}
.login-logo .logo-icon {
  background: var(--accent); color: #fff;
  width: 36px; height: 36px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.login-error {
  background: #fef2f2; border: 1px solid #fca5a5;
  border-radius: var(--radius-sm); padding: .65rem .9rem;
  font-size: .84rem; color: var(--danger); margin-bottom: 1rem;
}
[data-theme="dark"] .login-error { background: #2d0a0a; border-color: #991b1b; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th { background: var(--bg-input); font-weight: 600; font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
th, td { padding: .65rem .9rem; border-bottom: 1px solid var(--border); text-align: left; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(232,93,38,.03); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(3px);
  z-index: 200;
  display: none; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 100%; max-width: 480px;
  box-shadow: var(--shadow-lg);
  animation: fadeUp .2s ease;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--text-muted); }
.modal-footer { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.25rem; }

/* ── Toast ── */
.toast-container {
  position: fixed; bottom: 1.25rem; right: 1.25rem;
  z-index: 500; display: flex; flex-direction: column; gap: .5rem;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .7rem 1rem;
  font-size: .85rem;
  box-shadow: var(--shadow-lg);
  animation: slideIn .2s ease;
  display: flex; align-items: center; gap: .5rem;
  max-width: 300px;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-info    { border-left: 3px solid var(--accent-2); }

/* ── Animations ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ── Utility ── */
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; }
.mt-4 { margin-top: 1rem; }
.mb-3 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); font-size: .85rem; }
.text-sm    { font-size: .85rem; }
.text-center { text-align: center; }
.fw-600 { font-weight: 600; }
.hidden { display: none !important; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.section-title { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; }
.empty-state {
  text-align: center; padding: 3rem 1rem; color: var(--text-muted);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: .75rem; }

/* ──────────────────────────────────────────
   RESPONSIVE — Mobile
   ────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  .sidebar {
    transform: translateX(-240px);
    width: 240px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
  }
  .sidebar-overlay.open { display: block; }

  .main-content { margin-left: 0; }
  .hamburger { display: block; }
  .topbar { padding: .75rem 1rem; }
  .page-body { padding: 1rem; }

  .deck-grid { grid-template-columns: 1fr 1fr; gap: .75rem; }
  .flashcard { min-height: 220px; }
  .flashcard-text { font-size: 1.15rem; }
  .rating-row { grid-template-columns: repeat(2, 1fr); }
  .stats-row { grid-template-columns: repeat(2, 1fr); }

  .modal { padding: 1.25rem; }
  .login-box { padding: 1.75rem 1.25rem; }
}

@media (max-width: 400px) {
  .deck-grid { grid-template-columns: 1fr; }
}
