:root {
    --bg: #fbfbfb;
    --surface: #ffffff;
    --text: #1f2328;
    --text-muted: #59636e;
    --border: #d0d7de;
    --primary: #0969da;
    --danger: #cf222e;
    --think-bg: #f6f8fa;
    --user-bg: #eef5fc;
    --radius: 6px;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* Header & Config Box */
#top-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    gap: 1rem;
    will-change: transform;
}

.brand a {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}

.config-box {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.85rem;
    max-width: 520px;
    width: 100%;
}

.config-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: flex-end;
}

/* Inputs & Controls */
input[type="text"],
input[type="password"],
select,
textarea {
    font-family: inherit;
    font-size: 0.85rem;
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}

input[type="text"],
input[type="password"],
select {
    flex: 1;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
    white-space: nowrap;
}

.btn {
    font-size: 0.85rem;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover {
    background: #f3f4f6;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: #0854ad;
}

.btn-danger {
    color: var(--danger);
    border-color: var(--danger);
}

.hidden {
    display: none !important;
}

/* Furigana Toggling */
body.hide-furigana ruby rt {
    visibility: hidden;
    user-select: none;
}

/* Main Container */
.container {
    width: 100%;
    max-width: 100%;
    margin: 1rem 0;
    padding: 0 1.5rem;
}

.lesson-index ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

.lesson-index a {
    color: var(--primary);
    font-weight: 500;
    text-decoration: none;
}

.lesson-index a:hover {
    text-decoration: underline;
}

/* Lesson View */
.lesson-title {
    margin-bottom: 0.75rem;
}

.explanation-box {
    background: var(--surface);
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 2rem;
}

/* Markdown Content & Nested List Indentation */
.explanation-box ul,
.explanation-box ol,
.chat-msg ul,
.chat-msg ol {
    padding-left: 1.75rem;
    margin: 0.5rem 0;
}

.explanation-box li,
.chat-msg li {
    margin: 0.25rem 0;
}

.reference-answers {
    margin: 0.25rem 0 0.5rem 1.25rem;
    padding: 0;
    list-style-type: disc;
}

.reference-answers li {
    margin-bottom: 0.2rem;
}

.section-title {
    margin: 2rem 0 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.3rem;
}

.item-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.prompt-text {
    font-size: 1.15rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

details {
    margin-top: 0.5rem;
}

summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
    user-select: none;
}

.details-content {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border);
}

.meta-block {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.meta-block strong {
    color: var(--text-muted);
}

/* Check mark and progress for answered items */
.check-mark-btn {
    background: none;
    border: none;
    padding: 0;
    margin: 0 0.35rem 0 0;
    cursor: pointer;
    font: inherit;
    font-weight: bold;
    color: #10b981;
    display: inline-flex;
    align-items: center;
    transition: opacity 0.15s, transform 0.1s;
}

.check-mark-btn:hover {
    opacity: 0.7;
    transform: scale(1.15);
}

.check-mark-btn:active {
    transform: scale(0.95);
}

.progress-ratio-btn {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    font: inherit;
    display: inline-flex;
    align-items: center;
    transition: opacity 0.15s, transform 0.1s;
}

.progress-ratio-btn:hover {
    opacity: 0.7;
    transform: scale(1.08);
}

.progress-ratio-btn:active {
    transform: scale(0.95);
}

/* Status colors apply directly to the button */
.progress-ratio-btn.progress-none {
    color: inherit;
}

.progress-ratio-btn.progress-partial {
    color: #f59e0b;
    font-weight: 600;
}

.progress-ratio-btn.progress-complete {
    color: #10b981;
    font-weight: 600;
}

/* Submission Div */
.submission-container {
    margin-top: 1rem;
}

.chat-history {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
}

.chat-msg {
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    border: 1px solid var(--border);
}

.chat-msg.user {
    background: var(--user-bg);
    align-self: flex-end;
    max-width: 85%;
}

.chat-msg.assistant {
    background: var(--surface);
    align-self: flex-start;
    width: 100%;
}

.thinking-block {
    background: var(--think-bg);
    border-left: 3px solid var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    white-space: pre-wrap;
}

.submission-controls {
    display: flex;
    gap: 0.5rem;
}

.submission-controls input {
    flex: 1;
}

/* Lesson Footer Navigation */
.lesson-nav {
    display: flex;
    justify-content: space-between;
    margin: 3rem 0;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: #24292f;
    color: #fff;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
    transition: opacity 0.2s ease;
}

/* Brand Column & Center Title */
.brand-col {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
}

.top-bar-title {
    font-size: 1.7rem;
    font-weight: 700;
    text-align: center;
    align-self: center;
    flex: 1;
}

/* Modal Dialog */
dialog#how-to-use-modal {
    max-width: 70%;
    width: 90%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    padding: 1.5rem;
    margin: auto;
}

dialog#how-to-use-modal::backdrop {
    background: rgba(0, 0, 0, 0.4);
}

.modal-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.75rem;
}

.modal-body {
    max-height: 70vh;
    overflow-y: auto;
}

.modal-body ul,
.modal-body ol {
    padding-left: 1.75rem;
    margin: 0.5rem 0;
}

.modal-body li {
    margin: 0.25rem 0;
}

.user-answer {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--think-bg);
    color: var(--text);
    font-weight: 500;
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

/* Adds a small gray label before the answer */
.user-answer:not(:empty)::before {
    content: "Your Response:";
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

.user-answer:empty {
    display: none;
}

.slider-card {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    background: transparent;
    padding: 0;
    margin: 0;
    box-shadow: none;
    min-width: 0;
    vertical-align: middle;

    transform: scale(var(--scale, 1));
    transform-origin: left center;
}

.slider-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Compact track */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 160px;
    height: 6px;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    background: #e2e8f0;
    vertical-align: middle;
    margin: 0;
}

/* Compact thumb (Chrome, Safari, Edge) */
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: var(--slider-color, #94a3b8);
    border: 2px solid #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    cursor: pointer;
}

/* Compact thumb (Firefox) */
input[type="range"]::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--slider-color, #94a3b8);
    border: 1.5px solid #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    cursor: pointer;
}

/* Inline number display */
.slider-value {
    font-size: 0.85rem;
    font-weight: 600;
    width: 12px;
    text-align: center;
    line-height: 1;
    color: var(--slider-color, #94a3b8);
}

/* Inline text badge */
.difficulty-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    min-height: 0;
    width: 48px;
    /* Fixed width prevents jitter while sliding */
    line-height: 1;
    color: var(--slider-color, #94a3b8);
}

/* ==========================================================================
   Sort Card & Controls
   ========================================================================== */
.lesson-index-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.lesson-index-header h1 {
  margin: 0;
}

.sort-card {
  display: inline-flex;
  flex-direction: column;     /* Stacks the label on top */
  align-items: flex-start;
  gap: 0.25rem;
}

.sort-card-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;             /* Subtle muted text */
  line-height: 1;
}

.sort-container {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.sort-select {
  padding: 0.35rem 0.65rem;
  font-size: 0.9rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background-color: #ffffff;
  color: #1e293b;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.sort-select:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.sort-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 0.75rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.sort-toggle-btn:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
}

/* Container to keep the star button aligned nicely beside the difficulty slider */
.difficulty-star-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Star Button */
.star-btn {
  background: transparent;
  border: none;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.15rem;
  color: #94a3b8; /* Default subtle outline color */
  transition: transform 0.15s ease, color 0.15s ease;
  user-select: none;
}

.star-btn:hover {
  transform: scale(1.2);
  color: #eab308;
}

/* Filled star state */
.star-btn.starred {
  color: #eab308; /* Yellow/Gold */
  text-shadow: 0 0 4px rgba(234, 179, 8, 0.4);
}