:root {
  color-scheme: light;

  --bg-0: #f3ede1;
  --bg-1: #ece3d2;

  --panel: rgba(255, 255, 255, 0.72);
  --panel-border: rgba(60, 48, 32, 0.1);
  --panel-border-strong: rgba(60, 48, 32, 0.18);

  --text-0: #2c241c;
  --text-1: #6d6153;
  --text-2: #9a8f7e;

  --accent: #b1592f;
  --accent-ink: #fff8ef;
  --accent-soft: rgba(177, 89, 47, 0.12);

  --teal: #3c6e63;

  --good: #3f8a5c;
  --good-soft: rgba(63, 138, 92, 0.14);
  --bad: #b84a3e;
  --bad-soft: rgba(184, 74, 62, 0.13);

  --tile-face: linear-gradient(160deg, #fffaf0, #f0e3c4);
  --tile-face-ink: #3a2d18;
  --tile-edge: #d7c290;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  font-size: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
button, [role="button"], input, label, .key { touch-action: manipulation; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-0);
}

body {
  color: var(--text-0);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif;
  padding: 16px;
  padding-block: 32px;
  min-height: 100dvh;
  overflow-x: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(60% 50% at 15% 0%, rgba(177, 89, 47, 0.06), transparent 60%),
    radial-gradient(50% 45% at 100% 100%, rgba(60, 110, 99, 0.07), transparent 60%),
    var(--bg-0);
}

/* ---------- background ---------- */

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.35;
  z-index: 0;
  pointer-events: none;
  will-change: transform;
}
.orb-1 {
  width: 40vmax; height: 40vmax;
  top: -16vmax; left: -16vmax;
  background: radial-gradient(circle at 30% 30%, #e7c9a1, transparent 70%);
  animation: drift1 40s ease-in-out infinite;
}
.orb-2 {
  width: 34vmax; height: 34vmax;
  bottom: -14vmax; right: -12vmax;
  background: radial-gradient(circle at 70% 70%, #bcd4c9, transparent 70%);
  animation: drift2 46s ease-in-out infinite;
}

@keyframes drift1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(3vmax, 4vmax) scale(1.06); }
}
@keyframes drift2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-3vmax, -3vmax) scale(1.05); }
}

@media (prefers-reduced-motion: reduce) {
  .bg-orb { animation: none; }
}

/* ---------- layout ---------- */

.app {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.app-header {
  text-align: center;
  padding-top: 8px;
}

.logo {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.9rem, 6.5vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--text-0);
}
.logo span {
  color: var(--accent);
}

.tagline {
  margin: 6px 0 0;
  color: var(--text-1);
  font-size: 0.95rem;
}

/* ---------- segmented controls ---------- */

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.segmented {
  position: relative;
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
  box-shadow: 0 1px 2px rgba(60, 48, 32, 0.06);
}

.seg-btn {
  position: relative;
  z-index: 2;
  border: none;
  background: transparent;
  color: var(--text-1);
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.25s ease;
  white-space: nowrap;
}
.seg-btn small {
  display: block;
  font-size: 0.64rem;
  font-weight: 600;
  opacity: 0.75;
  letter-spacing: 0.04em;
}
.seg-btn.active { color: var(--accent-ink); }
.seg-btn:not(.active):hover { color: var(--text-0); }

.seg-thumb {
  position: absolute;
  z-index: 1;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: 80px;
  border-radius: 999px;
  background: var(--accent);
  transition: left 0.32s cubic-bezier(.65,0,.35,1), width 0.32s cubic-bezier(.65,0,.35,1);
  box-shadow: 0 3px 10px rgba(177, 89, 47, 0.28);
}

/* ---------- input card ---------- */

.input-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 26px 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 16px 40px rgba(60, 48, 32, 0.1);
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

#wordInput {
  width: 100%;
  font: inherit;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-0);
  background: #fffdf8;
  border: 1.5px solid var(--panel-border-strong);
  border-radius: var(--radius-md);
  padding: 14px 44px 14px 18px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#wordInput::placeholder {
  color: var(--text-2);
  text-transform: none;
  font-weight: 500;
  letter-spacing: normal;
}
#wordInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
#wordInput.is-valid { border-color: var(--good); box-shadow: 0 0 0 4px var(--good-soft); }
#wordInput.is-invalid { border-color: var(--bad); box-shadow: 0 0 0 4px var(--bad-soft); }

.clear-btn {
  position: absolute;
  right: 10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(60,48,32,0.07);
  color: var(--text-1);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.clear-btn:hover { background: rgba(60,48,32,0.13); color: var(--text-0); }
.clear-btn:active { transform: scale(0.9); }

/* ---------- tiles ---------- */

.tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 56px;
}

.tile {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 9px;
  background: var(--tile-face);
  border: 1px solid var(--tile-edge);
  box-shadow: 0 3px 0 var(--tile-edge), 0 6px 14px rgba(60, 48, 32, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--tile-face-ink);
  font-family: Georgia, "Times New Roman", serif;
  animation: tilePop 0.32s cubic-bezier(.3,1.6,.5,1) both;
  transform-origin: bottom center;
}

.tile .pt {
  position: absolute;
  bottom: 3px;
  right: 5px;
  font-size: 0.58rem;
  font-weight: 700;
  font-family: Georgia, serif;
  opacity: 0.7;
}

@keyframes tilePop {
  0% { opacity: 0; transform: translateY(10px) scale(0.5) rotate(-6deg); }
  70% { opacity: 1; transform: translateY(-3px) scale(1.05) rotate(2deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0deg); }
}

.tiles.valid .tile {
  animation: tileGood 0.5s ease both;
  animation-delay: var(--d, 0s);
}
.tiles.invalid .tile {
  animation: tileBad 0.42s ease both;
  animation-delay: var(--d, 0s);
}

@keyframes tileGood {
  0% { box-shadow: 0 3px 0 var(--tile-edge), 0 6px 14px rgba(60,48,32,0.18); }
  40% { box-shadow: 0 3px 0 var(--good), 0 0 0 4px var(--good-soft); transform: translateY(-5px); }
  100% { box-shadow: 0 3px 0 var(--good), 0 0 0 3px var(--good-soft); transform: translateY(0); }
}

@keyframes tileBad {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px) rotate(-2deg); }
  40% { transform: translateX(4px) rotate(2deg); }
  60% { transform: translateX(-3px) rotate(-1deg); }
  80% { transform: translateX(2px) rotate(1deg); }
}
.tiles.invalid .tile {
  box-shadow: 0 3px 0 var(--bad), 0 0 0 3px var(--bad-soft);
}

/* ---------- result ---------- */

.result {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.02rem;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 10px;
  border-radius: 999px;
  animation: badgeIn 0.3s cubic-bezier(.3,1.4,.4,1) both;
}
.result-badge.good { background: var(--good-soft); color: var(--good); }
.result-badge.bad { background: var(--bad-soft); color: var(--bad); }

.result-badge .icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.result-badge.good .icon { background: var(--good); color: #f3fbf6; }
.result-badge.bad .icon { background: var(--bad); color: #fdf3f1; }

@keyframes badgeIn {
  0% { opacity: 0; transform: scale(0.8) translateY(4px); }
  100% { opacity: 1; transform: scale(1); }
}

.result-score {
  color: var(--text-1);
  font-weight: 600;
  font-size: 0.9rem;
}
.result-score b { color: var(--text-0); font-size: 1rem; }

.hint {
  margin: 0;
  color: var(--text-2);
  font-size: 0.78rem;
}
.hint kbd {
  background: rgba(60,48,32,0.07);
  border: 1px solid var(--panel-border-strong);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.72rem;
  font-family: inherit;
}

/* ---------- history ---------- */

.history-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  animation: cardIn 0.4s ease both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.history-card h2 {
  margin: 0 0 12px;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  font-weight: 700;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--panel-border-strong);
  background: #fffdf8;
  cursor: pointer;
  color: var(--text-1);
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
  animation: chipIn 0.3s ease both;
}
.history-chip:hover { background: #fffaf0; transform: translateY(-1px); }
.history-chip:active { transform: translateY(0) scale(0.97); }
.history-chip .dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0;
}
.history-chip.good .dot { background: var(--good); }
.history-chip.bad .dot { background: var(--bad); }

@keyframes chipIn {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

/* ---------- music player bar ---------- */

:root {
  --player-h: 92px;
}

.player-bar {
  position: fixed;
  z-index: 60;
  right: 20px;
  bottom: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 10px 22px rgba(44, 36, 28, 0.28);
  display: flex;
  align-items: center;
  overflow: hidden;
  transition:
    right 0.5s cubic-bezier(.4,0,.2,1),
    bottom 0.5s cubic-bezier(.4,0,.2,1),
    width 0.5s cubic-bezier(.4,0,.2,1),
    height 0.5s cubic-bezier(.4,0,.2,1),
    border-radius 0.5s cubic-bezier(.4,0,.2,1),
    background 0.4s ease,
    box-shadow 0.4s ease;
}

.player-bar.open {
  right: 0;
  bottom: 0;
  width: 100%;
  height: var(--player-h);
  padding-left: 16px;
  border-radius: 22px 22px 0 0;
  background: var(--panel);
  backdrop-filter: blur(20px);
  box-shadow: 0 -12px 36px rgba(44, 36, 28, 0.18);
  border-top: 1px solid var(--panel-border);
}

.vinyl-btn {
  width: 60px;
  height: 60px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  padding: 6px;
  cursor: pointer;
  background: transparent;
  transition: transform 0.18s ease;
  position: relative;
}
.vinyl-btn:hover { transform: scale(1.04); }
.vinyl-btn:active { transform: scale(0.96); }

/* circular progress ring filling the padding gap around the disc */
.vinyl-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(
    from -90deg,
    var(--accent) calc(var(--progress, 0) * 1%),
    rgba(60, 48, 32, 0.16) 0
  );
  transition: background 0.2s linear;
  z-index: 0;
}

.vinyl {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background:
    repeating-radial-gradient(
      circle at 50% 50%,
      #1b1814 0px, #1b1814 2.2px,
      #262220 2.2px, #262220 4.4px
    );
  border: 1px solid #0f0d0b;
  position: relative;
  z-index: 1;
}
.vinyl.spinning {
  animation: vinylSpin 2.6s linear infinite;
}
@keyframes vinylSpin {
  to { transform: rotate(360deg); }
}

.vinyl-label {
  position: absolute;
  top: 50%; left: 50%;
  width: 36%; height: 36%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent) 55%, #8f431f 100%);
}
.vinyl-label::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 14%; height: 14%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #1b1814;
}

@media (prefers-reduced-motion: reduce) {
  .vinyl.spinning { animation: none; }
}

.player-content {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
  padding: 0 16px 0 8px;
  opacity: 0;
  transform: translateX(8px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  transition-delay: 0s;
}
.player-bar.open .player-content {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
  transition-delay: 0.15s;
}

/* transport */
.transport {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.transport-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
.transport-btn:hover { background: rgba(60, 48, 32, 0.08); color: var(--text-0); }
.transport-btn:active { transform: scale(0.9); }

.play-pause-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 14px rgba(177, 89, 47, 0.32);
  transition: transform 0.15s ease, background 0.15s ease;
}
.play-pause-btn .icon-play { transform: translateX(1px); }
.play-pause-btn .icon-pause { display: none; }
.play-pause-btn.is-playing .icon-play { display: none; }
.play-pause-btn.is-playing .icon-pause { display: block; }
.play-pause-btn:hover { transform: scale(1.05); }
.play-pause-btn:active { transform: scale(0.94); }

.player-info {
  min-width: 0;
  flex: 1;
}
.player-track-name {
  margin: 0;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-track-sub {
  margin: 2px 0 0;
  font-size: 0.72rem;
  color: var(--text-2);
}

.volume-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  flex-shrink: 0;
  width: 110px;
}
.volume-icon { display: flex; align-items: center; }
.volume-row input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
}

.airplay-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-1);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  display: none;
}
.airplay-btn.available { display: flex; }
.airplay-btn:hover { background: rgba(60, 48, 32, 0.08); color: var(--text-0); }
.airplay-btn.active { color: var(--accent); }

.player-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(60, 48, 32, 0.07);
  color: var(--text-1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.player-close:hover { background: rgba(60, 48, 32, 0.13); color: var(--text-0); }

/* ---------- hamburger + drawer ---------- */

.hamburger {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 70;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(12px);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 2px 8px rgba(60, 48, 32, 0.08);
  transition: background 0.15s ease, transform 0.15s ease;
}
.hamburger:hover { transform: translateY(-1px); }
.hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: var(--text-0);
  transition: transform 0.28s ease, opacity 0.2s ease;
}
.hamburger[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.hamburger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 80;
  width: 280px;
  max-width: 82vw;
  padding: 76px 16px 24px;
  background: var(--bg-1);
  border-right: 1px solid var(--panel-border);
  box-shadow: 8px 0 32px rgba(44, 36, 28, 0.14);
  transform: translateX(-102%);
  transition: transform 0.34s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.drawer.open { transform: translateX(0); }

.drawer-title {
  margin: 0 8px 8px;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-2);
  font-weight: 700;
}

.app-link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-md);
  padding: 12px 12px;
  cursor: pointer;
  font: inherit;
  color: var(--text-1);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.app-link:hover { background: rgba(60, 48, 32, 0.05); }
.app-link.active {
  background: var(--accent-soft);
  border-color: rgba(177, 89, 47, 0.3);
}
.app-link-icon {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}
.app-link-name {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-0);
}
.app-link-desc {
  display: block;
  font-size: 0.75rem;
  color: var(--text-2);
  margin-top: 2px;
}

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 75;
  background: rgba(30, 24, 18, 0.32);
  opacity: 0;
  animation: scrimIn 0.25s ease forwards;
}
@keyframes scrimIn { to { opacity: 1; } }

/* ---------- app views ---------- */

.app-view {
  display: flex;
  flex-direction: column;
  gap: 22px;
  animation: viewIn 0.3s ease both;
}
@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- wordle duel ---------- */

.duel-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 16px 40px rgba(60, 48, 32, 0.1);
  animation: duelFade 0.4s ease;
}

/* smooth fades between lobby / waiting / wheel / game */
@keyframes duelFade {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.duel-game { animation: duelFade 0.45s ease; }
.duel-spin.fade-out {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.26s ease, transform 0.26s ease;
}
@media (prefers-reduced-motion: reduce) {
  .duel-panel, .duel-game { animation: none; }
  .duel-spin.fade-out { transition: none; }
}

.duel-btn {
  border: 1px solid var(--panel-border-strong);
  background: #fffdf8;
  color: var(--text-0);
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 13px 22px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}
.duel-btn:hover { background: #fffaf0; }
.duel-btn:active { transform: scale(0.98); }
.duel-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 6px 16px rgba(177, 89, 47, 0.28);
  width: 100%;
}
.duel-btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 8px 14px;
}
.duel-btn.ghost:hover { background: rgba(60, 48, 32, 0.05); color: var(--text-0); }

.duel-or {
  display: flex;
  align-items: center;
  width: 100%;
  color: var(--text-2);
  font-size: 0.8rem;
}
.duel-or::before, .duel-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--panel-border);
}
.duel-or span { padding: 0 12px; }

.join-form {
  display: flex;
  gap: 8px;
  width: 100%;
}
#joinCode {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-align: center;
  color: var(--text-0);
  background: #fffdf8;
  border: 1.5px solid var(--panel-border-strong);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#joinCode::placeholder { letter-spacing: 0.12em; color: var(--text-2); font-weight: 600; }
#joinCode:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.duel-msg { margin: 0; font-size: 0.85rem; font-weight: 600; min-height: 1.1em; text-align: center; }
.duel-msg.error { color: var(--bad); }
.duel-msg.ok { color: var(--good); }

.duel-setup-title { margin: 0; font-weight: 700; color: var(--text-0); }
.duel-setup-text { margin: 0; font-size: 0.85rem; color: var(--text-1); line-height: 1.6; text-align: center; }
.duel-setup-text code {
  background: rgba(60, 48, 32, 0.08);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 0.82em;
}

.waiting-label { margin: 0; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-2); font-weight: 700; }
.room-code {
  font-family: Georgia, serif;
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--accent);
  padding: 8px 4px 8px 16px;
}
.waiting-note { margin: 4px 0 0; color: var(--text-1); font-size: 0.9rem; }
.waiting-note::after { content: ""; }

/* spin-for-first-move wheel */
.duel-spin { gap: 20px; }
.spin-title { margin: 0; font-weight: 700; color: var(--text-1); }
.wheel { position: relative; width: 210px; height: 210px; }
.wheel-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(to bottom, var(--accent-soft) 0 50%, rgba(60, 48, 32, 0.07) 50% 100%);
  border: 3px solid var(--panel-border-strong);
  box-shadow: 0 10px 28px rgba(60, 48, 32, 0.16), inset 0 0 0 6px #fffdf8;
}
.wheel-label {
  position: absolute;
  left: 0; right: 0;
  text-align: center;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  font-family: Georgia, serif;
}
.wheel-label.top { top: 20%; color: var(--accent); }
.wheel-label.bottom { bottom: 20%; color: var(--text-2); }
.wheel-needle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 42%;
  background: linear-gradient(var(--accent), #8f431f);
  border-radius: 4px 4px 2px 2px;
  transform-origin: bottom center;
  transform: translate(-50%, -100%) rotate(var(--spin-to, 0deg));
  z-index: 2;
  will-change: transform;
}
.wheel-needle.spinning {
  animation: needleSpin 2.8s cubic-bezier(.17, .67, .21, 1) both;
}
@keyframes needleSpin {
  from { transform: translate(-50%, -100%) rotate(var(--spin-from, 0deg)); }
  to   { transform: translate(-50%, -100%) rotate(var(--spin-to, 0deg)); }
}
.wheel-needle::before {
  content: "";
  position: absolute;
  top: -11px; left: 50%;
  transform: translateX(-50%);
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 13px solid var(--accent);
}
.wheel-hub {
  position: absolute;
  top: 50%; left: 50%;
  width: 22px; height: 22px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #fffdf8;
  border: 3px solid var(--accent);
  z-index: 3;
}
.spin-result { margin: 0; min-height: 1.3em; font-weight: 800; font-size: 1.1rem; color: var(--accent); }

/* game */
.duel-game { display: flex; flex-direction: column; align-items: center; gap: 18px; }

.turn-banner {
  width: 100%;
  text-align: center;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 1rem;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text-1);
  transition: background 0.2s ease, color 0.2s ease;
}
.turn-banner.your-turn { background: var(--accent-soft); color: var(--accent); border-color: rgba(177,89,47,0.3); }
.turn-banner.their-turn { background: rgba(60,48,32,0.05); color: var(--text-2); }

.boards {
  display: flex;
  gap: 18px;
  width: 100%;
  justify-content: center;
}
.board-col { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: 1; max-width: 240px; min-width: 0; }
.board-label { margin: 0; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-2); font-weight: 700; }

.board { display: grid; grid-template-rows: repeat(6, 1fr); gap: 5px; width: 100%; }
.board-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.wtile {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  border: 2px solid var(--panel-border-strong);
  background: #fffdf8;
  font-weight: 800;
  font-size: clamp(0.9rem, 4.5vw, 1.4rem);
  text-transform: uppercase;
  color: var(--text-0);
  font-family: Georgia, serif;
}
.wtile.filled { border-color: var(--text-2); animation: tilePop 0.15s ease; }
.wtile.correct { background: var(--good); border-color: var(--good); color: #fff; }
.wtile.present { background: #d9a53a; border-color: #d9a53a; color: #fff; }
.wtile.absent  { background: #9a8f7e; border-color: #9a8f7e; color: #fff; }
.board-opponent .wtile { font-size: 0; } /* hide rival's letters, show colors only */

/* staggered flip reveal — each tile flips and shows its colour in turn */
.wtile.revealing {
  animation: tileReveal 0.6s ease both;
  animation-delay: calc(var(--rev-i, 0) * 0.28s);
}
@keyframes tileReveal {
  0%   { transform: rotateX(0deg);   background: #fffdf8; border-color: var(--text-2); color: transparent; }
  49%  { transform: rotateX(-90deg); background: #fffdf8; border-color: var(--text-2); color: transparent; }
  50%  { transform: rotateX(-90deg); }   /* past here, the tile's colour class takes over */
  100% { transform: rotateX(0deg); }
}
@media (prefers-reduced-motion: reduce) {
  .wtile.revealing { animation: none; }
}

.duel-result {
  width: 100%;
  text-align: center;
  padding: 14px;
  border-radius: var(--radius-md);
  font-weight: 700;
  animation: badgeIn 0.4s cubic-bezier(.3,1.4,.4,1) both;
}
.duel-result.win { background: var(--good-soft); color: var(--good); }
.duel-result.lose { background: var(--bad-soft); color: var(--bad); }
.duel-result.draw { background: rgba(60,48,32,0.06); color: var(--text-1); }
.duel-result .word { display: block; margin-top: 4px; font-family: Georgia, serif; letter-spacing: 0.12em; }
.duel-result .again { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.duel-result .again .duel-btn.primary { width: auto; min-width: 160px; }

/* on-screen keyboard */
.keyboard { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 480px; }
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1;
  min-width: 0;
  height: 48px;
  border: none;
  border-radius: 7px;
  background: #e7dcc7;
  color: var(--text-0);
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, transform 0.08s ease, color 0.12s ease;
}
.key:active { transform: scale(0.94); }
.key.wide { flex: 1.5; font-size: 0.72rem; }
.key.correct { background: var(--good); color: #fff; }
.key.present { background: #d9a53a; color: #fff; }
.key.absent { background: #b7ab97; color: #fff; }
.keyboard.disabled { opacity: 0.5; pointer-events: none; }

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  :root { --player-h: 92px; }
  .player-content { gap: 12px; padding: 0 12px 0 6px; }
  .volume-row { width: 80px; }
}

@media (max-width: 440px) {
  .tile { width: 40px; height: 40px; font-size: 1.1rem; border-radius: 8px; }
  .input-card { padding: 20px 16px 16px; }
  .seg-btn { padding: 8px 12px; font-size: 0.78rem; }
  .volume-row { display: none; }
  .player-content { gap: 6px; }
  .boards { gap: 10px; }
  .key { height: 42px; font-size: 0.8rem; }
  .room-code { font-size: 1.8rem; }
}
