/* PimPhid typing game — notebook look */
.tg-page {
  --tg-paper: #fbfaf6;
  --tg-rule: #dde5f0;
  --tg-margin: #eba7a7;
  --tg-floor: #dc2626;
  --tg-ink: #1f2937;
  --tg-muted: #6b7280;
  --tg-accent: #2563eb;
  --tg-ok: #15803d;
  max-width: 920px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  margin: 0 auto;
  padding: 24px 20px 48px;
}
[data-theme="dark"] .tg-page {
  --tg-paper: #1b1d22;
  --tg-rule: #2b3140;
  --tg-margin: #6b3434;
  --tg-floor: #f87171;
  --tg-ink: #e5e7eb;
  --tg-muted: #9ca3af;
  --tg-accent: #60a5fa;
  --tg-ok: #4ade80;
}
.tg-hero { text-align: center; margin-bottom: 18px; }
.tg-hero h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); margin: 0 0 6px; }
.tg-hero p { color: var(--tg-muted); margin: 0; }

.tg-banner {
  background: var(--tg-accent); color: #fff; border-radius: 12px;
  padding: 10px 14px; margin-bottom: 12px; text-align: center; font-weight: 600;
}
.tg-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.tg-modes { display: flex; flex-wrap: wrap; gap: 6px; }
.tg-modes button {
  border: 1px solid var(--tg-rule); background: transparent; color: var(--tg-ink);
  border-radius: 8px; padding: 6px 12px; font: inherit; cursor: pointer;
}
.tg-modes button[aria-pressed="true"] { background: var(--tg-ink); color: var(--tg-paper); border-color: var(--tg-ink); }
.tg-modes button[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.tg-stats { display: flex; gap: 14px; color: var(--tg-muted); font-size: .95rem; }
.tg-stats #tgScore { color: var(--tg-ink); font-weight: 700; }

.tg-field {
  position: relative; overflow: hidden; height: 420px; border-radius: 14px;
  border: 1px solid var(--tg-rule);
  background-color: var(--tg-paper);
  background-image: repeating-linear-gradient(to bottom, transparent 0 31px, var(--tg-rule) 31px 32px);
  cursor: text;
}
.tg-field::before { content: ""; position: absolute; top: 0; bottom: 0; left: 40px; width: 2px; background: var(--tg-margin); }
.tg-floor { position: absolute; left: 0; right: 0; bottom: 24px; height: 2px; background: var(--tg-floor); }
.tg-field.is-paused::after {
  content: "หยุดชั่วคราว · กด Esc เพื่อเล่นต่อ"; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--tg-paper) 80%, transparent); color: var(--tg-ink); font-weight: 600;
}
.tg-word {
  position: absolute; top: 0; left: 0; white-space: nowrap; will-change: transform;
  font-family: "Sarabun", "IBM Plex Sans Thai", serif; font-size: 22px; line-height: 32px;
  color: var(--tg-ink); padding: 0 4px;
}
.tg-word.tg-swap { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; color: #b45309; }
[data-theme="dark"] .tg-word.tg-swap { color: #fbbf24; }
.tg-word.prefix { text-decoration: underline; text-decoration-color: var(--tg-accent); text-decoration-thickness: 2px; text-underline-offset: 4px; }
.tg-word.struck {
  text-decoration: line-through; text-decoration-color: var(--tg-ok); text-decoration-thickness: 3px;
  color: var(--tg-muted); transition: opacity .6s ease .1s; opacity: 0;
}
.tg-word.fallen { color: var(--tg-floor); font-weight: 700; }

.tg-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px;
  align-items: center; justify-content: center; text-align: center; padding: 20px;
}
.tg-overlay[hidden], .tg-result[hidden] { display: none; }
.tg-overlay p { color: var(--tg-muted); margin: 0; max-width: 420px; }
.tg-btn {
  font: inherit; font-weight: 600; border-radius: 8px; padding: 10px 20px; cursor: pointer;
  border: 1px solid var(--tg-ink); background: var(--tg-ink); color: var(--tg-paper);
}
.tg-btn.secondary { background: transparent; color: var(--tg-ink); border-color: var(--tg-rule); text-decoration: none; display: inline-block; }

.tg-inputrow { display: flex; gap: 8px; margin-top: 10px; }
.tg-inputrow input {
  flex: 1; min-width: 0; font: inherit; font-size: 1.15rem; padding: 10px 14px;
  border-radius: 12px; border: 1px solid var(--tg-rule); background: var(--tg-paper); color: var(--tg-ink);
}
.tg-inputrow input:focus { outline: 2px solid var(--tg-accent); outline-offset: 1px; }
.tg-inputrow input.wrong { outline-color: var(--tg-floor); }

.tg-result {
  margin-top: 16px; border: 1px solid var(--tg-rule); border-radius: 14px; padding: 20px;
  background: var(--tg-paper); color: var(--tg-ink); text-align: center;
}
.tg-result .tg-final { font-size: 3.4rem; font-weight: 700; line-height: 1.1; }
.tg-result .tg-meta { color: var(--tg-muted); margin: 4px 0 14px; }
.tg-titlebox { display: inline-block; padding: 4px 0 12px; margin-bottom: 8px; border-bottom: 2px solid var(--tg-accent); }
.tg-titlebox small { display: block; color: var(--tg-muted); }
.tg-titlebox strong { display: block; font-size: 1.5rem; color: var(--tg-accent); }
.tg-missed { list-style: none; padding: 0; margin: 4px 0 12px; color: var(--tg-floor); font-weight: 600; }
.tg-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.tg-name { font: inherit; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--tg-rule); background: transparent; color: var(--tg-ink); }
.tg-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--tg-ink); color: var(--tg-paper); padding: 10px 16px; border-radius: 12px;
}
.tg-toast[hidden] { display: none; }

@media (max-width: 640px) {
  .tg-page { padding: 12px 12px 40px; }
  .tg-game { display: flex; flex-direction: column; }
  .tg-game .tg-inputrow { order: -1; margin: 0 0 8px; }
  .tg-game .tg-bar { order: -2; margin-bottom: 8px; }
  .tg-game.is-playing .tg-modes { display: none; }
  .tg-hero p { display: none; }
  .tg-word { font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .tg-word.struck { transition: none; }
}

.tg-lessons-link { color: var(--tg-muted); margin: 0 0 10px; }
.tg-meta span + span::before { content: ""; display: inline-block; width: 1px; height: .9em; background: var(--tg-rule); margin: 0 10px; vertical-align: middle; }
