:root {
  --tt-bg: #07172e;
  --tt-panel: #05203f;
  --tt-panel-soft: #0b3259;
  --tt-cyan: #45f5ff;
  --tt-green: #45d19b;
  --tt-green-soft: #63ffb4;
  --tt-magenta: #ff55cc;
  --tt-text: #eafcff;
  --tt-border: #4c78ff;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-width: 1120px;
  overflow-x: auto;
  background: radial-gradient(circle at top, #0b2b4f 0%, var(--tt-bg) 55%, #020a16 100%);
  color: var(--tt-text);
  font-family: "Courier New", "Noto Sans Mono TC", "Consolas", monospace;
  letter-spacing: 0;
}

.tt-shell {
  width: min(1240px, calc(100vw - 48px));
  min-width: 1100px;
  max-width: 1240px;
  margin: 12px auto 24px;
  padding: 12px;
  background-color: rgba(2, 12, 28, 0.75);
  border: 2px solid var(--tt-border);
  border-radius: 2px;
  box-shadow: 0 0 30px rgba(0, 255, 247, 0.06);
}

h1, h2 {
  margin: 0 0 6px 0;
}

h1 {
  color: #9cfffd;
  text-shadow: 0 0 8px rgba(84, 255, 255, 0.45);
}

h2 {
  color: var(--tt-cyan);
  border-bottom: 1px dashed rgba(84, 255, 255, 0.3);
  padding-bottom: 6px;
  margin-bottom: 10px;
}

p, .tt-meta {
  color: #d9f5ff;
}

.tt-titlebar {
  border: 2px solid #0c4f7f;
  background: linear-gradient(to right, #0a2f50, #0a2f50 60%, #12396a);
  padding: 10px;
}

.tt-statusline {
  margin-top: 8px;
  color: var(--tt-magenta);
  border: 1px dashed var(--tt-magenta);
  padding: 6px;
  background-color: #090b1e;
}

.tt-menu {
  margin-top: 10px;
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tt-menu .tt-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.tt-subtitle-panel {
  margin-top: 10px;
  min-height: 42px;
  display: flex;
  gap: 10px;
  align-items: center;
  border: 1px solid #2f7cb2;
  background: rgba(1, 9, 22, 0.88);
  padding: 8px 10px;
  color: #eafcff;
  box-shadow: inset 0 0 12px rgba(69, 245, 255, 0.08);
}

.tt-subtitle-panel.is-active {
  border-color: var(--tt-cyan);
  box-shadow: inset 0 0 12px rgba(69, 245, 255, 0.12), 0 0 8px rgba(69, 245, 255, 0.12);
}

.tt-subtitle-speaker {
  flex: 0 0 auto;
  min-width: 86px;
  border-right: 1px solid rgba(234, 252, 255, 0.28);
  padding-right: 10px;
  font-weight: 700;
  color: var(--tt-cyan);
}

.tt-subtitle-text {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.45;
  color: #f3feff;
}

.speaker-narrator {
  color: #9cfffd;
}

.speaker-tutor {
  color: #b5ffce;
}

.speaker-enemy-girl {
  color: #ff93df;
}

.speaker-alarm {
  color: #ffda6b;
}

.speaker-grunt {
  color: #ffa26d;
}

.tt-btn {
  border: 2px solid var(--tt-border);
  border-radius: 0;
  background: linear-gradient(to bottom, #11345f, #0a2241);
  color: var(--tt-text);
  padding: 8px 12px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  text-transform: uppercase;
}

.tt-btn:hover,
.tt-btn:focus-visible {
  background: linear-gradient(to bottom, #2a5ca3, #11345f);
  box-shadow: 0 0 6px rgba(96, 180, 255, 0.5);
}

.tt-btn-active {
  background: linear-gradient(to bottom, #4d8dff, #1f5cad);
  color: #fff;
}

.tt-btn-subtle {
  border-color: #3f5f80;
  background: #0a2e4e;
}

.tt-screen {
  display: none;
  margin-top: 10px;
  border: 2px solid #184f80;
  background: linear-gradient(180deg, rgba(8, 27, 49, 0.92), rgba(4, 14, 31, 0.95));
  padding: 12px;
}

.tt-screen.is-active {
  display: block;
  animation: tt-fade-in 160ms ease-in;
}

.tt-practice-toolbar,
.tt-invaders-controls,
.tt-leaderboard-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

select,
.tt-input {
  color: #fff;
  border-radius: 0;
  border: 1px solid #5aa6d7;
  background: #031329;
  padding: 8px 10px;
  font: inherit;
}

.tt-target-window {
  min-height: 120px;
  padding: 10px;
  border: 1px solid #29598b;
  background: rgba(2, 12, 26, 0.7);
  white-space: pre-wrap;
  line-height: 1.8;
  margin-bottom: 8px;
}

.tt-char {
  display: inline-block;
  padding: 0 1px;
  border-radius: 2px;
}

.tt-char.pending {
  color: #9abcc9;
}

.tt-char.correct {
  color: var(--tt-green-soft);
  font-weight: 700;
}

.tt-char.wrong {
  color: #ff9bd4;
  background: rgba(255, 53, 158, 0.25);
}

.tt-char.cursor {
  outline: 1px solid var(--tt-magenta);
  background: rgba(255, 85, 204, 0.18);
}

.tt-stats {
  color: #d0f8ff;
  border-left: 2px solid var(--tt-magenta);
  padding-left: 8px;
  margin-top: 6px;
}

.tt-meta {
  font-size: 14px;
  color: #9af7d8;
  min-height: 20px;
  margin-bottom: 8px;
}

.tt-result {
  margin-top: 10px;
  min-height: 50px;
  border: 1px solid #2d5b8b;
  background: rgba(6, 27, 53, 0.9);
  padding: 10px;
}

.tt-result .tt-rank {
  color: var(--tt-green-soft);
}

.tt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin-top: 10px;
}

.tt-table th,
.tt-table td {
  border: 1px solid #2a527b;
  padding: 6px;
  text-align: left;
}

.tt-table th {
  color: #7af7ff;
  background: #0b3b66;
}

#tt-invaders-canvas {
  width: min(100%, 1024px);
  max-width: 100%;
  min-height: 600px;
  height: 66vh;
  border: 2px solid #2469a5;
  display: block;
  background: linear-gradient(to bottom, #00111d, #001a2c);
  margin-bottom: 8px;
}

.tt-invaders-word {
  color: #9cf5ff;
}

.tt-keyboard-diagram {
  border: 1px solid #2b587d;
  padding: 10px;
  background: rgba(3, 18, 37, 0.8);
  overflow-x: auto;
}

.tt-key-row {
  margin-bottom: 6px;
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  align-items: center;
}

.tt-key-row-number {
  margin-left: 0;
}

.tt-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 34px;
  width: 34px;
  min-width: 34px;
  height: 30px;
  margin-right: 0;
  border: 2px solid #265b84;
  line-height: 1;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  transition: background-color 80ms linear, color 80ms linear, box-shadow 80ms linear, transform 80ms linear;
}

.tt-k-number {
  background: rgba(69, 245, 255, 0.12);
  border-color: #2f7cb2;
}

.tt-key-active {
  color: #fff;
  background: rgba(255, 85, 204, 0.45);
  border-color: var(--tt-magenta);
  box-shadow: 0 0 12px rgba(255, 85, 204, 0.65);
  transform: translateY(1px);
}

.tt-key-pulse {
  animation: tt-key-pulse 180ms linear;
}

.tt-k-left {
  background: rgba(95, 208, 174, 0.2);
}

.tt-k-right {
  background: rgba(85, 128, 232, 0.2);
}

.tt-k-space {
  flex-basis: min(80%, 520px);
  width: min(80%, 520px);
  min-width: 220px;
  text-align: left;
  padding-left: 12px;
  justify-content: flex-start;
}

.tt-key-row-space {
  margin-top: 4px;
}

.tt-key-legend {
  margin-top: 8px;
  display: grid;
  gap: 6px;
  font-size: 13px;
}

.tt-space {
  display: inline-block;
  width: 0.5em;
}

@keyframes tt-fade-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes tt-key-pulse {
  0% { filter: brightness(1); }
  50% { filter: brightness(1.7); }
  100% { filter: brightness(1); }
}

.tt-fx-layer {
  pointer-events: none;
  position: relative;
  min-height: 0;
  z-index: 3;
}

.tt-shake {
  animation: tt-shake 150ms linear;
}

@keyframes tt-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.tt-hit-marker,
.tt-hit-spark,
.tt-combo-pulse,
.tt-fx-bubble,
.tt-boss-banner,
.tt-challenge-panel,
.tt-powerup-token {
  position: absolute;
  z-index: 5;
  font-family: inherit;
}

.tt-hit-marker {
  color: #b5ffce;
  font-weight: 800;
  text-shadow: 0 0 8px rgba(99, 255, 180, 0.8);
  transform: translate(-50%, -50%);
  animation: tt-hit-pop 620ms ease-out forwards;
}

.tt-hit-spark {
  color: #ffcc45;
  text-shadow: 0 0 8px rgba(255, 204, 69, 0.8);
  animation: tt-hit-spark 420ms ease-out forwards;
}

.tt-combo-pulse {
  left: 50%;
  top: 14px;
  color: #ffcc45;
  text-shadow: 0 0 10px #ffcc45;
  font-weight: 800;
  transform: translateX(-50%);
  animation: tt-combo-rise 920ms ease-out forwards;
}

.tt-fx-bubble {
  right: 12px;
  top: 12px;
  max-width: min(320px, calc(100vw - 32px));
  border: 1px solid #45f5ff;
  background: rgba(0, 10, 24, 0.9);
  color: #eafcff;
  padding: 7px 9px;
  overflow-wrap: anywhere;
  line-height: 1.4;
  box-shadow: 0 0 12px rgba(69, 245, 255, 0.14);
}

.tt-boss-banner {
  left: 10px;
  right: 10px;
  top: 8px;
  border: 2px double #ff55cc;
  background: #050818;
  color: #ffcc45;
  text-align: center;
  padding: 10px;
  text-shadow: 0 0 10px #ff55cc;
  animation: tt-boss-banner 2400ms ease-out forwards;
}

.tt-challenge-panel {
  left: 50%;
  top: 48px;
  max-width: min(720px, calc(100vw - 36px));
  transform: translateX(-50%);
  border: 2px solid #ffcc45;
  background: rgba(5, 8, 24, 0.96);
  color: #fff3a6;
  padding: 10px 14px;
  text-align: center;
  font-weight: 800;
  overflow-wrap: anywhere;
  box-shadow: 0 0 16px rgba(255, 204, 69, 0.18);
}

.tt-powerup-token {
  right: 14px;
  bottom: 10px;
  cursor: pointer;
  pointer-events: auto;
  border: 1px solid #45f5ff;
  color: #45f5ff;
  background: #031329;
  padding: 6px 8px;
  font-weight: 800;
  box-shadow: 0 0 10px rgba(69, 245, 255, 0.16);
}

.tt-base-low-hp {
  box-shadow: 0 0 30px rgba(255, 85, 204, 0.18), inset 0 0 14px rgba(255, 85, 204, 0.08);
}

.tt-low-fx .tt-shake,
.tt-low-fx .tt-combo-pulse,
.tt-low-fx .tt-hit-marker,
.tt-low-fx .tt-hit-spark,
.tt-low-fx .tt-boss-banner {
  animation: none;
}

.tt-low-fx .tt-hit-spark {
  display: none;
}

@keyframes tt-hit-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  20% { opacity: 1; transform: translate(-50%, -70%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -125%) scale(0.88); }
}

@keyframes tt-hit-spark {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-18px); }
}

@keyframes tt-combo-rise {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(0.88); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -28px) scale(1.08); }
}

@keyframes tt-boss-banner {
  0% { opacity: 0; transform: translateY(-8px); }
  14%, 80% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-8px); }
}

@media (max-width: 700px) {
  .tt-shell {
    margin: 12px auto 24px;
    border-left: 2px solid var(--tt-border);
    border-right: 2px solid var(--tt-border);
  }
  .tt-key-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    align-items: center;
  }
  .tt-key {
    width: 34px;
  }
}
