/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Gentium Plus', Georgia, 'Times New Roman', serif;
  font-size: 18px;
  line-height: 1.7;
  color: #3d2e22;
  background-color: #f2ece5;
  min-height: 100vh;
}

/* ===== Layout ===== */
.container {
  max-width: 860px;
  margin: 0 auto;
  background: #fffcf8;
  padding: 0;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(60,40,20,0.08), 0 4px 12px rgba(60,40,20,0.05);
  overflow: hidden;
}

/* ===== Navigation ===== */
nav {
  display: flex;
  align-items: baseline;
  gap: 24px;
  padding: 16px 36px;
  background: #f8f2ea;
  border-bottom: 1px solid #e0d5c8;
}

nav a {
  color: #5c4a3a;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}

nav a:visited {
  color: #5c4a3a;
}

nav a:hover {
  color: #993b2b;
  text-decoration: none;
}

nav .nav-brand {
  font-size: 1.8rem;
  font-weight: 700;
  color: #993b2b;
  letter-spacing: -0.02em;
}

nav .nav-brand:visited {
  color: #993b2b;
}

nav .nav-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  align-self: center;
}

nav .lang-switch,
nav .theme-switch {
  font-size: inherit;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border: 1.5px solid #c8bba8;
  border-radius: 4px;
  color: #7a6b58;
  transition: all 0.15s;
  cursor: pointer;
  background: none;
  text-decoration: none;
  display: inline-block;
  line-height: 1.4;
}

nav .lang-switch:hover,
nav .theme-switch:hover {
  border-color: #993b2b;
  color: #993b2b;
}

/* Undo button overrides for theme-switch */
nav .theme-switch {
  padding: 3px 10px;
  border-radius: 4px;
  transform: none;
  box-shadow: none;
}

nav .theme-switch:hover {
  transform: none;
  box-shadow: none;
  background: none;
}

/* Content padding inside container */
.container > *:not(nav) {
  padding-left: 36px;
  padding-right: 36px;
}

.container > *:not(nav):last-child {
  padding-bottom: 36px;
}

/* ===== Typography ===== */
h1 {
  color: #2c1e14;
  font-size: 1.75rem;
  font-weight: 700;
  margin-top: 32px;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

h2 {
  color: #3d2e22;
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 28px;
  margin-bottom: 12px;
}

/* ===== Home columns ===== */
.home-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-top: 16px;
}

.home-left .description {
  margin-top: 0;
}

.home-left .description::first-letter {
  font-size: 3.2em;
  float: left;
  line-height: 0.8;
  margin-right: 6px;
  margin-top: 4px;
  color: #993b2b;
  font-weight: 700;
}

.home-right h2 {
  margin-top: 0;
}

@media (max-width: 640px) {
  .home-columns {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

a {
  color: #993b2b;
  transition: color 0.15s;
}

a:visited {
  color: #993b2b;
}

a:hover {
  color: #b34432;
}

/* ===== Buttons ===== */
button, .btn {
  font-family: inherit;
  background-color: #993b2b;
  color: white !important;
  border: none;
  padding: 10px 22px;
  border-radius: 6px;
  cursor: pointer;
  font-size: inherit;
  font-weight: 500;
  text-decoration: none;
  display: inline-block;
  transition: all 0.15s;
}

button:hover, .btn:hover {
  background-color: #b34432;
  color: white !important;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(153, 59, 43, 0.3);
}

button:active, .btn:active {
  transform: translateY(0);
}

.btn:visited {
  color: white !important;
}

button.delete {
  background-color: #7f1d1d;
}

button.delete:hover {
  background-color: #991b1b;
  box-shadow: 0 2px 4px rgba(127, 29, 29, 0.3);
}

button.secondary {
  background-color: #7a6b58;
}

button.secondary:hover {
  background-color: #5c4a3a;
  box-shadow: 0 2px 4px rgba(92, 74, 58, 0.3);
}

.btn-small {
  font-size: 0.8em;
  padding: 6px 14px;
  border-radius: 5px;
}

.btn-wrapper {
  margin-bottom: 20px;
  margin-top: 8px;
}

/* ===== Forms ===== */
label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: inherit;
  color: #3d2e22;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="datetime-local"],
select {
  font-family: inherit;
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid #c8bba8;
  border-radius: 6px;
  font-size: inherit;
  margin-bottom: 16px;
  background: #fffcf8;
  color: #2c1e14;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
input[type="datetime-local"]:focus,
select:focus {
  outline: none;
  border-color: #993b2b;
  box-shadow: 0 0 0 3px rgba(153, 59, 43, 0.1);
}

/* Narrower fields for small inputs */
input[type="number"],
input[name="pin"] {
  max-width: 200px;
}

.field-hint {
  display: block;
  color: #9a8b78;
  margin-top: -10px;
  margin-bottom: 16px;
}

/* ===== Badges ===== */
.badge {
  font-size: 0.8em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 3px 8px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: middle;
}

.badge-language {
  background: #f5ece0;
  color: #993b2b;
}

.badge-locked {
  background: #fef3cd;
  color: #8a6d1b;
}

.badge-revealed {
  background: #dcfce7;
  color: #15803d;
}

.language-badge {
  font-size: 0.8em;
  font-weight: 600;
  background: #f5ece0;
  color: #993b2b;
  padding: 3px 10px;
  border-radius: 4px;
  margin-left: 10px;
  vertical-align: middle;
}

/* ===== Messages ===== */
.error {
  background-color: #fdf0ee;
  border: 1px solid #e8bdb6;
  color: #7f1d1d;
  padding: 14px 18px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 0.8em;
}

.loading {
  text-align: center;
  padding: 24px;
  color: #7a6b58;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e0d5c8;
  border-top-color: #993b2b;
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  color: #9a8b78;
  padding: 40px 0;
  text-align: center;
  font-size: 0.8em;
}

/* ===== Home Page ===== */
.description {
  margin-bottom: 24px;
  color: #6b5c4a;
  line-height: 1.8;
}

.feature-list {
  margin: 12px 0 28px 24px;
  color: #5c4a3a;
}

.feature-list li {
  margin-bottom: 10px;
  padding-left: 4px;
}

/* ===== Dictation Cards ===== */
.dictation-card {
  border: 1px solid #e0d5c8;
  padding: 20px 22px;
  margin-bottom: 14px;
  border-radius: 8px;
  background: #f8f2ea;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.dictation-card:hover {
  border-color: #c4946e;
  box-shadow: 0 2px 8px rgba(153, 59, 43, 0.06);
}

.dictation-title {
  margin-bottom: 8px;
  color: #2c1e14;
}

.dictation-link {
  text-decoration: none;
  color: #993b2b;
  font-weight: 600;
}

.dictation-link:visited {
  color: #993b2b;
}

.dictation-link:hover {
  text-decoration: underline;
}

.dictation-date {
  color: #9a8b78;
  margin-bottom: 12px;
  font-style: italic;
}

/* ===== Dictation Detail ===== */
.topics-line {
  margin-bottom: 6px;
  font-size: 0.8em;
}

.date-text {
  color: #9a8b78;
  font-size: 0.8em;
}

.actions-wrapper {
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.cancel-link {
  color: #7a6b58;
}

.audio-container {
  background: #f5ece0;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 8px;
}

.sentence-item {
  margin-bottom: 16px;
  padding: 18px;
  background: #fffcf8;
  border-radius: 8px;
  border: 1px solid #e0d5c8;
}

.sentence-number {
  font-weight: 700;
  color: #993b2b;
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

audio {
  width: 100%;
  margin-bottom: 14px;
  border-radius: 8px;
}

.sentence-text {
  padding: 12px 16px;
  background: #fdf0ee;
  border-left: 3px solid #993b2b;
  margin-top: 12px;
  color: #3d2e22;
  border-radius: 0 6px 6px 0;
  font-size: 0.8em;
  line-height: 1.8;
}

#createForm {
  padding-bottom: 36px;
}

.delete-form {
  margin-top: 32px;
  padding-top: 24px;
  padding-bottom: 36px;
  border-top: 1px solid #e0d5c8;
  text-align: right;
}

/* ===== Footer ===== */
footer {
  background: #2c1e14;
  color: #b8a898;
  margin-top: 48px;
}

.footer-content {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 32px 8em;
}

footer p {
  margin-bottom: 4px;
}

/* ===== Legacy (keep for backward compat) ===== */
.countdown-container {
  background: #fef3cd;
  border: 1px solid #fde68a;
  color: #8a6d1b;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 20px;
  text-align: center;
}

.countdown-timer {
  font-size: 28px;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
  margin-top: 8px;
}

/* ========================================
   Dark Mode — warm parchment & oxblood
   Inspired by aged books, vellum, and
   early printing with red ink on dark leather.

   Applied via .dark class on <html>, with
   media query fallback for no-JS.
   ======================================== */
html.dark body,
html:not(.light) body {
  color: #d4c8b8;
  background-color: #151210;
}

html.dark .container,
html:not(.light) .container {
  background: #211c17;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4), 0 4px 14px rgba(0,0,0,0.25);
}

/* Nav */
html.dark nav,
html:not(.light) nav {
  background: #1c1712;
  border-bottom-color: #3a3028;
}

html.dark nav a,
html.dark nav a:visited,
html:not(.light) nav a,
html:not(.light) nav a:visited {
  color: #9a8b78;
}

html.dark nav .nav-brand,
html.dark nav .nav-brand:visited,
html:not(.light) nav .nav-brand,
html:not(.light) nav .nav-brand:visited {
  color: #c4654e;
}

html.dark nav a:hover,
html:not(.light) nav a:hover {
  color: #c4654e;
}

html.dark nav .lang-switch,
html.dark nav .theme-switch,
html:not(.light) nav .lang-switch,
html:not(.light) nav .theme-switch {
  border-color: #4a3f34;
  color: #9a8b78;
}

html.dark nav .lang-switch:hover,
html.dark nav .theme-switch:hover,
html:not(.light) nav .lang-switch:hover,
html:not(.light) nav .theme-switch:hover {
  border-color: #c4654e;
  color: #c4654e;
}

/* Typography */
html.dark h1,
html:not(.light) h1 {
  color: #f0e6d8;
  border-bottom-color: #993b2b;
}

html.dark h2,
html:not(.light) h2 {
  color: #e0d5c5;
}

html.dark a,
html.dark a:visited,
html:not(.light) a,
html:not(.light) a:visited {
  color: #c4654e;
}

html.dark a:hover,
html:not(.light) a:hover {
  color: #d9856f;
}

/* Buttons */
html.dark button,
html.dark .btn,
html:not(.light) button,
html:not(.light) .btn {
  background-color: #993b2b;
}

html.dark button:hover,
html.dark .btn:hover,
html:not(.light) button:hover,
html:not(.light) .btn:hover {
  background-color: #b34432;
  box-shadow: 0 2px 6px rgba(153, 59, 43, 0.4);
}

html.dark button.delete,
html:not(.light) button.delete {
  background-color: #7f1d1d;
}

html.dark button.delete:hover,
html:not(.light) button.delete:hover {
  background-color: #991b1b;
  box-shadow: 0 2px 4px rgba(127, 29, 29, 0.4);
}

html.dark button.secondary,
html:not(.light) button.secondary {
  background-color: #5c5145;
}

html.dark button.secondary:hover,
html:not(.light) button.secondary:hover {
  background-color: #6e6256;
}

/* Forms */
html.dark label,
html:not(.light) label {
  color: #c4b8a6;
}

html.dark input[type="text"],
html.dark input[type="number"],
html.dark input[type="datetime-local"],
html.dark select,
html:not(.light) input[type="text"],
html:not(.light) input[type="number"],
html:not(.light) input[type="datetime-local"],
html:not(.light) select {
  background-color: #2a241d;
  border-color: #3e362c;
  color: #e8ddd0;
}

html.dark input[type="text"]:focus,
html.dark input[type="number"]:focus,
html.dark input[type="datetime-local"]:focus,
html.dark select:focus,
html:not(.light) input[type="text"]:focus,
html:not(.light) input[type="number"]:focus,
html:not(.light) input[type="datetime-local"]:focus,
html:not(.light) select:focus {
  border-color: #993b2b;
  box-shadow: 0 0 0 3px rgba(153, 59, 43, 0.15);
}

html.dark input::placeholder,
html:not(.light) input::placeholder {
  color: #6b5f52;
}

/* Badges */
html.dark .badge-language,
html.dark .language-badge,
html:not(.light) .badge-language,
html:not(.light) .language-badge {
  background: #2e2218;
  color: #c4654e;
}

html.dark .badge-locked,
html:not(.light) .badge-locked {
  background: #302818;
  color: #d4a94e;
}

html.dark .badge-revealed,
html:not(.light) .badge-revealed {
  background: #1a2e18;
  color: #7dba6a;
}

/* Messages */
html.dark .error,
html:not(.light) .error {
  background-color: #2e1412;
  border-color: #5c2420;
  color: #e8a09a;
}

html.dark .loading,
html:not(.light) .loading {
  color: #7a6e60;
}

html.dark .spinner,
html:not(.light) .spinner {
  border-color: #3a3228;
  border-top-color: #c4654e;
}

html.dark .empty-state,
html:not(.light) .empty-state {
  color: #7a6e60;
}

/* Home */
html.dark .description,
html:not(.light) .description {
  color: #9a8b78;
}

html.dark .feature-list,
html:not(.light) .feature-list {
  color: #c4b8a6;
}

/* Cards */
html.dark .dictation-card,
html:not(.light) .dictation-card {
  border-color: #3a3028;
  background: #1c1712;
}

html.dark .dictation-card:hover,
html:not(.light) .dictation-card:hover {
  border-color: #993b2b;
  box-shadow: 0 2px 8px rgba(153, 59, 43, 0.1);
}

html.dark .dictation-title,
html:not(.light) .dictation-title {
  color: #f0e6d8;
}

html.dark .dictation-link,
html.dark .dictation-link:visited,
html:not(.light) .dictation-link,
html:not(.light) .dictation-link:visited {
  color: #c4654e;
}

html.dark .dictation-date,
html:not(.light) .dictation-date {
  color: #7a6e60;
}

/* Detail */
html.dark .date-text,
html:not(.light) .date-text {
  color: #7a6e60;
}

html.dark .cancel-link,
html:not(.light) .cancel-link {
  color: #9a8b78;
}

html.dark .audio-container,
html:not(.light) .audio-container {
  background: #181310;
  border: 1px solid #2a241d;
}

html.dark .sentence-item,
html:not(.light) .sentence-item {
  background: #1c1712;
  border-color: #332b22;
}

html.dark .sentence-number,
html:not(.light) .sentence-number {
  color: #c4654e;
}

html.dark .sentence-text,
html:not(.light) .sentence-text {
  background: #2e1f18;
  border-left-color: #993b2b;
  color: #d4c8b8;
}

html.dark .delete-form,
html:not(.light) .delete-form {
  border-top-color: #3a3028;
}

html.dark audio,
html:not(.light) audio {
  filter: invert(1) hue-rotate(180deg);
}

/* Footer */
html.dark footer,
html:not(.light) footer {
  background: #0e0b08;
  color: #5a5048;
}

/* Legacy */
html.dark .countdown-container,
html:not(.light) .countdown-container {
  background: #302818;
  border-color: #8a6e2e;
  color: #d4a94e;
}

html.dark .field-hint,
html:not(.light) .field-hint {
  color: #7a6e60;
}

/* ========================================
   Light mode explicit override
   When .light is set, ensure light styles
   win over the html:not(.light) fallback.
   ======================================== */
html.light body {
  color: #3d2e22;
  background-color: #f2ece5;
}

html.light .container {
  background: #fffcf8;
  box-shadow: 0 1px 3px rgba(60,40,20,0.08), 0 4px 12px rgba(60,40,20,0.05);
}

html.light nav {
  background: #f8f2ea;
  border-bottom-color: #e0d5c8;
}

html.light nav a,
html.light nav a:visited { color: #5c4a3a; }
html.light nav a:hover { color: #993b2b; }

html.light nav .lang-switch,
html.light nav .theme-switch {
  border-color: #c8bba8;
  color: #7a6b58;
}
html.light nav .lang-switch:hover,
html.light nav .theme-switch:hover {
  border-color: #993b2b;
  color: #993b2b;
}

html.light h1 { color: #2c1e14; border-bottom-color: #993b2b; }
html.light h2 { color: #3d2e22; }
html.light a, html.light a:visited { color: #993b2b; }
html.light a:hover { color: #b34432; }

html.light button, html.light .btn { background-color: #993b2b; }
html.light button:hover, html.light .btn:hover {
  background-color: #b34432;
  box-shadow: 0 2px 4px rgba(153, 59, 43, 0.3);
}
html.light button.delete { background-color: #7f1d1d; }
html.light button.delete:hover { background-color: #991b1b; }
html.light button.secondary { background-color: #7a6b58; }

html.light label { color: #3d2e22; }
html.light input[type="text"],
html.light input[type="number"],
html.light input[type="datetime-local"],
html.light select {
  background: #fffcf8; border-color: #c8bba8; color: #2c1e14;
}
html.light input[type="text"]:focus,
html.light input[type="number"]:focus,
html.light input[type="datetime-local"]:focus,
html.light select:focus {
  border-color: #993b2b;
  box-shadow: 0 0 0 3px rgba(153, 59, 43, 0.1);
}

html.light .badge-language, html.light .language-badge { background: #f5ece0; color: #993b2b; }
html.light .badge-locked { background: #fef3cd; color: #8a6d1b; }
html.light .badge-revealed { background: #dcfce7; color: #15803d; }

html.light .error { background-color: #fdf0ee; border-color: #e8bdb6; color: #7f1d1d; }
html.light .loading { color: #7a6b58; }
html.light .empty-state { color: #9a8b78; }
html.light .description { color: #6b5c4a; }
html.light .feature-list { color: #5c4a3a; }

html.light .dictation-card { border-color: #e0d5c8; background: #f8f2ea; }
html.light .dictation-card:hover { border-color: #c4946e; box-shadow: 0 2px 8px rgba(153,59,43,0.06); }
html.light .dictation-title { color: #2c1e14; }
html.light .dictation-link, html.light .dictation-link:visited { color: #993b2b; }
html.light .dictation-date { color: #9a8b78; }
html.light .date-text { color: #9a8b78; }
html.light .cancel-link { color: #7a6b58; }

html.light .audio-container { background: #f5ece0; border: none; }
html.light .sentence-item { background: #fffcf8; border-color: #e0d5c8; }
html.light .sentence-number { color: #993b2b; }
html.light .sentence-text { background: #fdf0ee; border-left-color: #993b2b; color: #3d2e22; }
html.light .delete-form { border-top-color: #e0d5c8; }
html.light audio { filter: none; }
html.light footer { background: #2c1e14; color: #b8a898; }
html.light .field-hint { color: #9a8b78; }
