* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f1115;
  color: #e8e8e8;
}

/* --- Kielivalitsin (FI/EN) --- */
.lang-toggle {
  background: none;
  border: 1px solid #444;
  color: #ccc;
  padding: 5px 9px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.lang-toggle:hover { background: #21252e; }
.auth-topbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}

/* --- Kirjautuminen / rekisteröinti --- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-box {
  background: #1a1d24;
  padding: 32px;
  border-radius: 14px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
.auth-box h1 {
  font-size: 22px;
  margin: 0 0 20px;
  text-align: center;
}
.auth-box input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: 8px;
  border: 1px solid #333;
  background: #0f1115;
  color: #fff;
  font-size: 15px;
}
.auth-box button {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: #4a7dff;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.auth-box button:hover { background: #3a68e0; }
.auth-error {
  color: #ff6b6b;
  font-size: 13px;
  margin-bottom: 10px;
  min-height: 16px;
}
.auth-link {
  text-align: center;
  margin-top: 14px;
  font-size: 13px;
  color: #999;
}
.auth-link a { color: #4a7dff; }

/* --- Chat --- */
.chat-wrap {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.chat-header {
  padding: 12px 16px;
  background: #1a1d24;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #262a33;
}
.chat-header button {
  background: none;
  border: 1px solid #444;
  color: #ccc;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.chat-header button.danger-btn {
  border-color: #e0473e;
  color: #ff8a80;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  position: relative;
  max-width: 75%;
  background: #1a1d24;
  padding: 8px 12px;
  border-radius: 12px;
  align-self: flex-start;
}
.msg.own { align-self: flex-end; background: #2d4ea8; }
.msg .meta { font-size: 11px; color: #999; margin-bottom: 3px; }
.msg.own .meta { color: #cdd8f7; }
.media-wrap { margin-top: 4px; max-width: 100%; }
.media-wrap img, .media-wrap video {
  max-width: 100%;
  border-radius: 8px;
  display: block;
  background: #000;
}
.media-download-btn {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  color: #4a7dff;
  text-decoration: none;
  background: rgba(74,125,255,0.1);
  padding: 4px 10px;
  border-radius: 8px;
}

/* --- Oman viestin poistopainike --- */
.msg-delete-btn {
  position: absolute;
  top: 4px;
  right: -6px;
  transform: translateX(100%);
  background: none;
  border: none;
  color: #777;
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg:hover .msg-delete-btn,
.msg:active .msg-delete-btn {
  opacity: 1;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 10px;
  background: #1a1d24;
  border-top: 1px solid #262a33;
}
.composer input[type=text] {
  flex: 1;
  padding: 12px;
  border-radius: 20px;
  border: 1px solid #333;
  background: #0f1115;
  color: #fff;
}
.composer button, .composer label {
  background: #4a7dff;
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 14px;
}
.composer input[type=file] { display: none; }

.welcome-banner {
  margin: 10px 10px 0;
  padding: 12px 14px;
  background: #1c2b4a;
  border: 1px solid #2d4ea8;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  color: #d7e0ff;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.welcome-banner span { flex: 1; }
.welcome-banner button {
  background: none;
  border: none;
  color: #9fb3ff;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  line-height: 1;
}
.welcome-banner button:hover { color: #fff; }
.no-key-banner {
  background: #3a1c1c;
  border-color: #a83e3e;
  color: #ffd7d7;
}
.no-key-banner button {
  background: #4a7dff;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}

.back-link {
  color: #ccc;
  text-decoration: none;
  font-size: 20px;
  padding: 0 4px;
}

/* --- Huonelista --- */
.room-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-radius: 10px;
  margin-bottom: 6px;
  background: #1a1d24;
  cursor: pointer;
}
.room-item:hover { background: #21252e; }
.room-item-text { flex: 1; min-width: 0; }
.room-name { font-weight: 600; margin-bottom: 4px; }
.room-preview { font-size: 13px; color: #999; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-item.has-unread { background: #1c2436; }
.room-item.has-unread:hover { background: #232d44; }
.room-item.has-unread .room-name { color: #fff; }
.room-item.has-unread .room-preview { color: #c8ccd4; }
.room-badge {
  flex-shrink: 0;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: #4a7dff;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-hint { text-align: center; color: #777; padding: 40px 20px; font-size: 14px; }

/* --- Videopuhelu: PIP-layout (oma pieni, muut isot) --- */
.call-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #05060a;
  z-index: 100;
  flex-direction: column;
}
.call-overlay.active { display: flex; }
.call-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  grid-auto-rows: minmax(200px, 1fr);
  gap: 6px;
  padding: 6px;
  align-content: stretch;
  align-items: stretch;
}
.call-tile {
  position: relative;
  background: #14161c;
  border-radius: 10px;
  overflow: hidden;
  min-height: 200px;
}
.call-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.local-tile {
  position: absolute;
  bottom: 90px;
  right: 14px;
  width: 110px;
  z-index: 10;
}
.local-tile .call-tile {
  aspect-ratio: 3 / 4;
  min-height: 0;
  border: 2px solid rgba(255,255,255,0.25);
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
}
.local-tile .call-name-tag {
  font-size: 10px;
  padding: 1px 6px;
}
.call-name-tag {
  position: absolute;
  bottom: 6px;
  left: 8px;
  font-size: 12px;
  background: rgba(0,0,0,0.5);
  padding: 2px 8px;
  border-radius: 10px;
}
.call-controls {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 16px;
}
.call-controls button {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: #2a2e38;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}
.call-controls button.off { background: #ff6b6b; }
.call-controls button.hangup {
  background: #e0473e;
  width: auto;
  border-radius: 26px;
  padding: 0 22px;
  font-size: 15px;
}

/* --- Valikko (hub.html, vain omistajalle) --- */
.hub-wrap {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
}
.hub-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 18px;
  margin-bottom: 20px;
  border-bottom: 1px solid #262a33;
}
.hub-header button {
  background: none;
  border: 1px solid #444;
  color: #ccc;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}
.hub-tile {
  background: #1a1d24;
  border: 1px solid #262a33;
  border-radius: 14px;
  padding: 22px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: #e8e8e8;
}
.hub-tile:hover { background: #21252e; }
.hub-tile-icon { font-size: 30px; }
.hub-tile-name { font-size: 13px; font-weight: 600; text-align: center; }

.hub-help {
  margin-top: 34px;
  font-size: 12.5px;
  color: #999;
}
.hub-help summary { cursor: pointer; color: #4a7dff; }
.hub-help p { line-height: 1.5; margin: 8px 0 0; }
.hub-help code {
  background: #0f1115;
  padding: 1px 5px;
  border-radius: 5px;
  color: #4a7dff;
  word-break: break-all;
}
.hub-help pre {
  background: #0f1115;
  border: 1px solid #262a33;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0 0;
  overflow-x: auto;
  font-size: 12px;
  color: #d0d4de;
}

/* --- Pelit: ristinolla + top-lista --- */
.games-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5,6,10,0.85);
  z-index: 90;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.games-overlay.active { display: flex; }
.games-panel {
  background: #1a1d24;
  border-radius: 14px;
  padding: 16px;
  width: 100%;
  max-width: 360px;
  max-height: 90vh;
  overflow-y: auto;
}
.games-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.games-panel-header button {
  background: none;
  border: none;
  color: #ccc;
  font-size: 18px;
  cursor: pointer;
}
.games-owner-toggle { margin-bottom: 12px; }
.games-toggle-btn {
  width: 100%;
  background: rgba(74,125,255,0.12);
  color: #4a7dff;
  border: 1px solid rgba(74,125,255,0.35);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
}
.games-toggle-btn.games-toggle-off {
  background: rgba(224,71,62,0.1);
  color: #ff8a80;
  border-color: rgba(224,71,62,0.3);
}
.ttt-status {
  text-align: center;
  font-size: 14px;
  color: #ccc;
  margin-bottom: 10px;
  min-height: 20px;
}
.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-width: 240px;
  margin: 0 auto;
}
.ttt-cell {
  aspect-ratio: 1;
  background: #0f1115;
  border: 1px solid #333;
  border-radius: 8px;
  font-size: 28px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
}
.ttt-cell:disabled { cursor: default; }
.ttt-cell.ttt-x { color: #4a7dff; }
.ttt-cell.ttt-o { color: #ff8a80; }
.ttt-actions {
  display: flex;
  justify-content: center;
  margin: 14px 0 4px;
}
.ttt-actions button {
  background: #4a7dff;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
}
.leaderboard {
  margin-top: 18px;
  border-top: 1px solid #2a2e38;
  padding-top: 12px;
}
.leaderboard-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #ccc;
}
.leaderboard-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid #232630;
}
.leaderboard-name { color: #fff; }
.leaderboard-stats { color: #999; }
.leaderboard-empty {
  font-size: 12px;
  color: #777;
  text-align: center;
  padding: 10px 0;
}
