.brand-text em {
  margin-left: 4px;
  padding: 2px 6px;
  color: var(--cyan-bright);
  font-size: 10px;
  font-style: normal;
  letter-spacing: 0.14em;
  border: 1px solid rgba(34, 211, 238, 0.28);
  border-radius: 999px;
  vertical-align: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

body[data-view="game"] .duel-app {
  height: auto;
  min-height: 100dvh;
}

.duel-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 26px 0 40px;
}

.duel-view {
  width: 100%;
}

.duel-hero {
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(28px, 5vw, 52px);
}

.duel-hero h1 {
  margin: 18px 0 0;
  font-size: clamp(34px, 5vw, 54px);
  line-height: 1.08;
  letter-spacing: -0.02em;
}

.duel-hero h1 span {
  background: linear-gradient(100deg, var(--cyan-bright), var(--cyan) 45%, #a78bfa 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.duel-hero .hero-copy {
  max-width: 46ch;
}

.login-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 26px;
  flex-wrap: wrap;
}

.duel-hint {
  margin: 14px 0 0;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.7;
}

.duel-panel {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(20px, 3vw, 30px);
}

.lobby-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.lobby-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 18px;
  align-items: start;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
}

.lobby-grid .duel-panel {
  max-width: none;
  margin: 0;
}

.duel-board {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.duel-board-item {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(9, 16, 27, 0.4);
}

.board-rank {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11px;
  text-align: center;
}

.duel-board-item:first-child .board-rank {
  color: var(--cyan-bright);
}

.board-pair {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.board-names {
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-meta {
  color: var(--faint);
  font-size: 11px;
}

.board-rounds {
  color: var(--cyan);
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

.board-rounds small {
  margin-left: 2px;
  color: var(--faint);
  font-size: 10px;
  font-weight: 400;
}

.rooms-panel {
  display: flex;
  flex-direction: column;
}

.open-rooms {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.room-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(9, 16, 27, 0.4);
}

.room-item-code {
  color: var(--cyan-bright);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.18em;
}

.room-item-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.room-item-host {
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-item-meta {
  color: var(--faint);
  font-size: 11px;
}

.room-item-join {
  padding: 6px 14px;
  font-size: 12px;
}

.rooms-panel .duel-hint {
  margin-top: 12px;
}

.create-btn {
  width: 100%;
  padding: 13px 18px;
}

.join-row {
  display: flex;
  gap: 10px;
}

.duel-input {
  flex: 1;
  min-width: 0;
  padding: 11px 13px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  background: rgba(8, 14, 24, 0.6);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.duel-input::placeholder {
  color: var(--faint);
}

.duel-input:focus {
  border-color: rgba(34, 211, 238, 0.55);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12);
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.24em;
  font-family: var(--mono);
  font-weight: 600;
}

.duel-input:disabled {
  opacity: 0.55;
}

.rule-list {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.65;
}

.rule-list b {
  display: inline-block;
  min-width: 34px;
  margin-right: 8px;
  padding: 0 7px;
  color: var(--cyan-bright);
  font-family: var(--mono);
  font-size: 11px;
  text-align: center;
  border: 1px solid rgba(34, 211, 238, 0.22);
  border-radius: 6px;
}

.room-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.room-label {
  display: block;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
}

.room-code {
  display: block;
  margin-top: 6px;
  color: var(--cyan-bright);
  font-family: var(--mono);
  font-size: clamp(30px, 5vw, 42px);
  letter-spacing: 0.22em;
  line-height: 1;
}

.room-players {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 20px;
}

.room-player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(9, 16, 27, 0.55);
}

.room-player.empty {
  justify-content: center;
  color: var(--faint);
  font-size: 12px;
  border-style: dashed;
}

.room-avatar {
  width: 42px;
  height: 42px;
  font-size: 17px;
}

.room-player-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.room-player-name {
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-player-tag {
  color: var(--faint);
  font-size: 11px;
}

.room-player-tag.ready {
  color: var(--mint);
}

.room-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.room-actions .btn {
  flex: 1;
}

.game-view {
  max-width: 100%;
}

.game-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  align-items: start;
}

.game-panel {
  max-width: none;
  min-height: 430px;
  display: flex;
  flex-direction: column;
}

.game-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.game-round {
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.game-phase {
  padding: 4px 10px;
  color: var(--cyan-bright);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  border: 1px solid rgba(34, 211, 238, 0.26);
  border-radius: 999px;
}

.phase-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding-top: 22px;
}

.phase-title {
  margin: 0;
  color: var(--text);
  font-size: clamp(20px, 2.6vw, 26px);
  font-weight: 700;
}

.phase-sub {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.word-row {
  display: flex;
  gap: 10px;
  margin-top: 26px;
}

.word-input {
  flex: 1;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-align: center;
}

.word-row .btn {
  flex: none;
  min-width: 96px;
}

.word-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  min-height: 30px;
}

.word-timer {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
}

.word-timer.counting {
  color: var(--amber);
  font-size: 22px;
  font-weight: 700;
}

.word-timer.urgent {
  color: var(--rose);
  animation: pulse-soft 1s ease-in-out infinite;
}

.word-status {
  color: var(--faint);
  font-size: 12px;
}

.word-status.active {
  color: var(--mint);
}

.reveal-words {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 24px;
}

.reveal-card {
  padding: 18px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(9, 16, 27, 0.55);
}

.reveal-name {
  color: var(--faint);
  font-size: 11.5px;
}

.reveal-word {
  margin-top: 10px;
  overflow: hidden;
  color: var(--cyan-bright);
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reveal-card.equal {
  border-color: rgba(52, 211, 153, 0.45);
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.12), 0 18px 40px rgba(16, 185, 129, 0.12);
}

.reveal-card.equal .reveal-word {
  color: var(--mint);
}

.seq-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.seq-segment {
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.08em;
}

.seq-mistakes {
  color: var(--faint);
  font-size: 12px;
}

.seq-mistakes.has-error {
  color: var(--rose);
}

.seq-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 26px;
  min-height: 64px;
}

.seq-key {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(9, 16, 27, 0.55);
  transition: transform 0.1s ease, border-color 0.1s ease, background 0.1s ease;
}

.seq-key.done {
  color: rgba(103, 232, 249, 0.42);
  border-color: rgba(34, 211, 238, 0.12);
}

.seq-key.current {
  color: #04121a;
  background: linear-gradient(145deg, var(--cyan-bright), var(--cyan));
  border-color: transparent;
  box-shadow: 0 8px 24px rgba(34, 211, 238, 0.35);
  transform: translateY(-3px);
}

.seq-keys.error .seq-key.current {
  background: var(--rose);
  box-shadow: 0 8px 24px rgba(251, 113, 133, 0.4);
}

.seq-keys.done .seq-key {
  color: var(--mint);
  border-color: rgba(52, 211, 153, 0.3);
}

.seq-hint-touch {
  display: none;
}

.seq-pad {
  display: none;
  grid-template-columns: repeat(3, 64px);
  grid-auto-rows: 64px;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
  user-select: none;
  -webkit-user-select: none;
}

.seq-pad-btn {
  display: grid;
  width: 64px;
  height: 64px;
  padding: 0;
  place-items: center;
  color: var(--text);
  font-family: var(--mono);
  font-size: 26px;
  border: 1px solid rgba(103, 232, 249, 0.26);
  border-radius: 16px;
  background: rgba(13, 25, 42, 0.85);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, background 0.08s ease, border-color 0.08s ease;
}

.seq-pad-btn[data-dir="U"] {
  grid-column: 2;
  grid-row: 1;
}

.seq-pad-btn[data-dir="L"] {
  grid-column: 1;
  grid-row: 2;
}

.seq-pad-btn[data-dir="D"] {
  grid-column: 2;
  grid-row: 2;
}

.seq-pad-btn[data-dir="R"] {
  grid-column: 3;
  grid-row: 2;
}

.seq-pad-btn:active {
  background: rgba(34, 211, 238, 0.22);
  border-color: rgba(103, 232, 249, 0.6);
  transform: scale(0.94);
}

.seq-pad.is-disabled {
  opacity: 0.35;
}

.seq-pad.is-disabled .seq-pad-btn {
  pointer-events: none;
}

.seq-opponent {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding-top: 26px;
  color: var(--faint);
  font-size: 11.5px;
}

.seq-track {
  flex: 1;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(93, 120, 158, 0.18);
}

.seq-track i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--mint));
  border-radius: inherit;
  transition: width 0.25s ease;
}

.history-panel {
  max-width: none;
  min-height: 430px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.history-empty {
  color: var(--faint);
  font-size: 12px;
}

.history-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(9, 16, 27, 0.4);
}

.history-round {
  display: flex;
  justify-content: space-between;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
}

.history-words {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 13px;
}

.history-word {
  flex: 1;
  overflow: hidden;
  padding: 5px 8px;
  color: var(--text);
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 7px;
  background: rgba(93, 120, 158, 0.1);
}

.history-item.equal .history-word {
  color: var(--mint);
  background: rgba(52, 211, 153, 0.12);
}

.history-equal {
  color: var(--mint);
  font-size: 10px;
}

.duel-result {
  width: min(560px, calc(100vw - 32px));
  max-height: min(86dvh, 720px);
  overflow: auto;
}

.duel-result h2 {
  margin: 14px 0 0;
  font-size: clamp(24px, 4vw, 32px);
}

.duel-result .duel-hint {
  margin-top: 10px;
}

.result-history {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}

.result-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.result-actions .btn {
  flex: 1;
}

.board-modal {
  text-align: left;
}

.board-modal .eyebrow {
  justify-content: flex-start;
  margin-bottom: 6px;
}

.board-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.board-modal-head > div {
  min-width: 0;
}

.board-modal-head h2 {
  margin: 0;
}

.board-modal-head .btn {
  flex: none;
}

.board-modal > .duel-hint {
  margin-top: 10px;
}

.board-modal .duel-board {
  margin-top: 14px;
}

.toast {
  z-index: 90;
}

@keyframes pulse-soft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@media (max-width: 980px) {
  .game-shell {
    grid-template-columns: 1fr;
  }

  .lobby-grid {
    grid-template-columns: 1fr;
  }

  .history-panel {
    min-height: 0;
  }

  .history-list {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .history-list > .history-item {
    flex: 1 1 240px;
  }
}

@media (max-width: 720px) {
  .duel-app {
    padding-top: max(14px, env(safe-area-inset-top));
    padding-right: max(14px, env(safe-area-inset-right));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    padding-left: max(14px, env(safe-area-inset-left));
  }

  .duel-main {
    padding: 18px 0 28px;
  }

  .brand-text {
    white-space: nowrap;
  }

  .duel-hero {
    padding: 24px 18px;
  }

  .duel-hero h1 {
    font-size: 34px;
  }

  .duel-panel {
    padding: 18px;
  }

  .code-input {
    font-size: 16px;
  }

  .room-players {
    grid-template-columns: 1fr;
  }

  .room-actions .btn,
  .result-actions .btn,
  .join-row .btn,
  .word-row .btn,
  .room-item-join {
    min-height: 44px;
  }

  .room-item-join {
    padding: 10px 16px;
    font-size: 13px;
  }

  .word-row {
    flex-direction: column;
  }

  .word-row .btn {
    width: 100%;
  }

  .seq-key {
    width: 47px;
    height: 47px;
    font-size: 21px;
  }

  .panel-heading span {
    display: none;
  }
}

@media (max-width: 720px), (hover: none) and (pointer: coarse) {
  .seq-hint-keyboard {
    display: none;
  }

  .seq-hint-touch {
    display: inline;
  }

  .seq-pad {
    display: grid;
  }
}

@media (max-width: 430px) {
  .brand-text {
    display: none;
  }

  .join-row {
    flex-direction: column;
  }

  .join-row .btn {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .topbar {
    gap: 10px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .topbar-actions .btn.ghost.small {
    padding-inline: 9px;
    font-size: 12px;
  }

  .user-chip {
    gap: 6px;
  }

  .user-name {
    display: none;
  }

  .user-logout {
    flex: none;
    padding-inline: 4px;
    white-space: nowrap;
  }
}

html[data-theme="light"] .duel-input,
html[data-theme="light"] .room-player,
html[data-theme="light"] .reveal-card,
html[data-theme="light"] .seq-key,
html[data-theme="light"] .seq-pad-btn,
html[data-theme="light"] .history-item,
html[data-theme="light"] .duel-board-item,
html[data-theme="light"] .room-item {
  background: rgba(255, 255, 255, 0.78);
}

html[data-theme="light"] .seq-track {
  background: rgba(8, 145, 178, 0.14);
}

html[data-theme="light"] .history-word {
  background: rgba(8, 145, 178, 0.08);
}

html[data-theme="light"] .seq-key.current {
  color: #04121a;
}

html[data-theme="light"] .brand-text em {
  color: #0e7490;
  border-color: rgba(8, 145, 178, 0.35);
}
