:root {
  color-scheme: dark;
  --page: #1a1c1e;
  --surface: #282b2d;
  --surface-soft: #323638;
  --input: #34393b;
  --text: #e5e7e7;
  --muted: #b3babc;
  --quiet: #9aa4a7;
  --border: #454b4e;
  --accent: #b8c3c2;
  --accent-soft: #3b4446;
  --accent-text: #202728;
  --own-bubble: #455356;
  --peer-bubble: #373e41;
  --warning: #d7b69a;
  --online: #a7bdb4;
  font-family: "Segoe UI", Arial, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --page: #d9dddc;
  --surface: #e8ebea;
  --surface-soft: #dde2e0;
  --input: #e3e7e5;
  --text: #26302f;
  --muted: #52605d;
  --quiet: #5e6c69;
  --border: #b8c2bf;
  --accent: #4d6260;
  --accent-soft: #d2dbd8;
  --accent-text: #f7faf8;
  --own-bubble: #c3d0cc;
  --peer-bubble: #d7ddda;
  --warning: #815536;
  --online: #587466;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--page);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-shell {
  width: min(1080px, calc(100% - 48px));
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  flex: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -.04em;
  text-decoration: none;
}
.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-size: 21px;
}
.brand-slash { padding: 0 2px; color: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.connection-status {
  min-width: 0;
  max-width: 175px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
#connectionStatusText { overflow: hidden; text-overflow: ellipsis; }
#connectionStatusText:empty { display: none; }
.status-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--quiet);
}
.connection-status[data-state="online"] .status-dot { background: var(--online); }
.connection-status[data-state="connecting"] .status-dot { background: var(--warning); }
.connection-status[data-state="offline"] .status-dot { background: #df8f94; }
.theme-toggle {
  width: 42px;
  height: 42px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  background: var(--surface);
  font-size: 21px;
  line-height: 1;
}
.theme-toggle:hover { background: var(--surface-soft); }

.main-layout {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 470px);
  align-items: center;
  gap: clamp(32px, 6vw, 80px);
  padding: 32px 0;
}
.intro { min-width: 0; }
.intro h1 {
  margin: 0;
  font-size: clamp(55px, 7vw, 88px);
  font-weight: 760;
  letter-spacing: -.08em;
  line-height: 1;
}
.intro h1 em { color: var(--accent); font-style: normal; }
.intro-copy { max-width: 390px; margin: 22px 0 0; color: var(--muted); font-size: 17px; line-height: 1.5; }

.game-card {
  width: 100%;
  min-width: 0;
  min-height: 530px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 20px 52px rgba(0, 0, 0, .13);
}
.card-header {
  min-height: 72px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { margin: 0; font-size: 19px; font-weight: 690; }
.timer {
  min-width: 76px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface-soft);
  font: 700 13px Consolas, monospace;
}
.timer[data-urgent="true"] { border-color: var(--warning); color: var(--warning); }
.timer-icon { font-size: 17px; line-height: 1; }
.view { flex: 1; min-height: 0; }
.landing-view, .search-view, .choice-view, .end-view {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 32px;
}
.view h3 { max-width: 390px; margin: 0; font-size: clamp(30px, 3.5vw, 42px); font-weight: 730; letter-spacing: -.055em; line-height: 1.13; }
.view p { margin: 14px 0 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.primary-button {
  width: min(100%, 350px);
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 30px;
  padding: 6px 6px 6px 18px;
  border: 0;
  border-radius: 11px;
  color: var(--accent-text);
  background: var(--accent);
  text-align: left;
  font-size: 15px;
  font-weight: 700;
}
.primary-button:hover:not(:disabled) { filter: brightness(1.08); }
.button-arrow { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 8px; background: rgba(255,255,255,.18); font-size: 25px; }
.view .privacy-note { max-width: 350px; margin-top: 15px; color: var(--quiet); font-size: 11px; }
.search-view, .choice-view { align-items: center; text-align: center; }
.search-radar {
  width: 54px;
  height: 54px;
  margin-bottom: 27px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.secondary-button {
  min-height: 44px;
  margin-top: 27px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface-soft);
  font-size: 14px;
}
.secondary-button:hover:not(:disabled) { border-color: var(--accent); }

.chat-view { min-height: 0; display: flex; flex-direction: column; }
.messages {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 13px;
  overflow-y: auto;
  padding: 24px;
  scrollbar-color: var(--border) transparent;
}
.message { max-width: min(78%, 480px); display: flex; flex-direction: column; gap: 4px; align-self: flex-start; }
.message.own { align-self: flex-end; align-items: flex-end; }
.message-bubble {
  max-width: 100%;
  padding: 11px 14px;
  border-radius: 15px 15px 15px 4px;
  color: var(--text);
  background: var(--peer-bubble);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.5;
}
.message.own .message-bubble { border-radius: 15px 15px 4px 15px; background: var(--own-bubble); }
.message-time { padding: 0 3px; color: var(--quiet); font-size: 10px; }
.system-message { align-self: center; max-width: 90%; color: var(--quiet); text-align: center; font-size: 11px; line-height: 1.5; }
.typing-indicator { min-height: 28px; display: flex; align-items: center; gap: 7px; padding: 0 24px; color: var(--muted); font-size: 12px; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); animation: typing 1.1s ease-in-out infinite; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
.message-form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 24px 0;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--input);
}
.message-form:focus-within { border-color: var(--accent); }
.message-form input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  padding: 0 10px;
  border: 0;
  outline: none;
  color: var(--text);
  background: transparent;
  font-size: 16px;
}
.message-form input::placeholder { color: var(--quiet); }
.message-form button {
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 9px;
  color: var(--accent-text);
  background: var(--accent);
  font-size: 25px;
}
.text-button {
  align-self: center;
  min-height: 44px;
  margin: 5px 0 9px;
  padding: 9px 12px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}
.text-button:hover { color: var(--text); text-decoration: underline; }

.choice-grid { width: min(100%, 380px); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 28px; }
.choice-button {
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text);
  background: var(--surface-soft);
  font-size: 16px;
  font-weight: 680;
}
.choice-button:hover:not(:disabled) { border-color: var(--accent); }
.choice-button span { margin-right: 4px; color: var(--accent); }
.choice-yes { border-color: var(--accent); color: var(--accent-text); background: var(--accent); }
.view .waiting-note { margin-top: 18px; color: var(--muted); font-size: 12px; }
.choice-leave { margin-top: 24px; }
.end-view h3 { font-size: clamp(30px, 3.5vw, 42px); }
.end-view p { max-width: 360px; }
.result-banner {
  margin: 18px 24px 0;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--accent-soft);
  font-size: 13px;
  line-height: 1.5;
}
.result-banner[data-correct="false"] { border-color: var(--warning); }
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 36px));
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text);
  background: var(--surface-soft);
  box-shadow: 0 12px 36px rgba(0,0,0,.2);
  font-size: 13px;
}

body:not([data-view="landing"]) .intro { display: none; }
body:is([data-view="landing"], [data-view="search"], [data-view="end"]) .card-header { display: none; }
body:not([data-view="landing"]) .main-layout { width: min(100%, 800px); display: flex; align-items: stretch; justify-content: center; margin: 0 auto; }
body:not([data-view="landing"]) .game-card { min-height: min(650px, calc(100dvh - 136px)); }
body[data-view="chat"] .site-shell { height: 100vh; height: 100dvh; overflow: hidden; }
body[data-view="chat"] .main-layout { min-height: 0; overflow: hidden; }
body[data-view="chat"] .game-card { min-height: 0; height: 100%; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes typing { 0%, 70%, 100% { transform: translateY(0); } 35% { transform: translateY(-4px); } }

@media (max-width: 850px) {
  .main-layout { grid-template-columns: 1fr; justify-items: center; gap: 26px; padding: 32px 0; }
  .intro { width: min(100%, 600px); }
  .intro h1 { font-size: clamp(52px, 9vw, 74px); }
  .game-card { max-width: 600px; min-height: 390px; }
}

@media (max-width: 600px) {
  .site-shell { width: min(100% - 28px, 520px); }
  .topbar { min-height: 62px; }
  .main-layout { gap: 24px; padding: 24px 0; }
  .intro h1 { font-size: clamp(42px, 11vw, 64px); }
  .intro-copy { margin-top: 12px; font-size: 14px; }
  .game-card { min-height: 340px; border-radius: 17px; }
  .card-header { min-height: 62px; padding: 12px 18px; }
  .card-header h2 { font-size: 17px; }
  .landing-view, .search-view, .choice-view, .end-view { padding: 26px 22px; }
  .view h3 { font-size: clamp(28px, 8vw, 36px); }
  .messages { padding: 18px 14px; }
  .message { max-width: 86%; }
  .message-form { margin: 4px 14px 0; }
  .typing-indicator { padding: 0 14px; }
  .result-banner { margin: 12px 14px 0; }
  body:not([data-view="landing"]) .main-layout { padding: 14px 0; }
  body:not([data-view="landing"]) .game-card { min-height: min(520px, calc(100dvh - 90px)); }
  body[data-view="chat"] .site-shell { width: 100%; }
  body[data-view="chat"] .topbar { padding: 0 14px; }
  body[data-view="chat"] .main-layout { width: 100%; padding: 0; }
  body[data-view="chat"] .game-card { height: 100%; min-height: 0; border: 0; border-radius: 0; }
  body[data-view="chat"] .chat-view { padding-bottom: env(safe-area-inset-bottom, 0px); }
}

@media (max-width: 380px) {
  .brand { font-size: 13px; }
  .brand-mark { width: 29px; height: 29px; }
  .topbar-actions { gap: 7px; }
  .connection-status { max-width: none; }
  .connection-status[data-state="connecting"] { max-width: 100px; font-size: 10px; }
  .connection-status:not([data-state="connecting"]) #connectionStatusText {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
  .theme-toggle { width: 40px; height: 40px; }
  .choice-grid { gap: 8px; }
  .choice-button { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
