/* Enhanced CSS - One Line Format */
:root {--bg:#0f172a; --muted:#94a3b8; --ink:#e2e8f0; --accent:#22d3ee; --danger:#fb7185; --warn:#f59e0b; --success:#10b981; --light-bg:rgba(255,255,255,0.03); --border:rgba(255,255,255,0.08); --highlight:rgba(34,211,238,0.15);}
* {box-sizing:border-box;}
html,body {height:100%; margin:0; padding:0;}
body {font-family: system-ui, -apple-system, Segoe UI, Roboto;background: radial-gradient(1200px 800px at 100% -10%, #0b1222 0%, var(--bg) 40%, #0b1222 100%);color: var(--ink);min-height: 100vh;padding: 0;overflow-x: hidden;overflow-y: hidden;position: fixed;width: 100vw;}
.viewport-wrapper {height: 100vh;overflow-y: auto;overflow-x: hidden;-webkit-overflow-scrolling: touch;overscroll-behavior-y: contain;scrollbar-width: thin;scrollbar-color: var(--accent) rgba(255, 255, 255, 0.05);}
.viewport-wrapper::-webkit-scrollbar {width: 8px;}
.viewport-wrapper::-webkit-scrollbar-track {background: rgba(255, 255, 255, 0.05);border-radius: 4px;}
.viewport-wrapper::-webkit-scrollbar-thumb {background: var(--accent);border-radius: 4px;}
.viewport-wrapper::-webkit-scrollbar-thumb:hover {background: #1dd1db;}
.app-container {width: 100%;max-width: 1400px;margin: 0 auto;padding: 20px;box-sizing: border-box;min-height: 100vh;}
.app {display: grid;grid-template-columns: 1.2fr 0.8fr;gap: 20px;align-items: start;width: 100%;max-width: 100%;box-sizing: border-box;}
.app.narrow {grid-template-columns:1fr;}
.card {background:var(--light-bg); border:1px solid var(--border); border-radius:16px; padding:20px; box-shadow:0 10px 30px rgba(0,0,0,0.35);}
.header {display:flex; justify-content:space-between; gap:12px; margin-bottom:20px; align-items:center;}
h1 {font-size:28px; margin:0; font-weight:700;}
h3 {margin:8px 0 12px; font-weight:600;}
h4 {margin:12px 0 8px; color:var(--accent); font-weight:600;}
.subtitle {color:var(--muted); font-size:14px; margin-top:6px; line-height:1.4;}
.toolbar {display:flex; flex-wrap:wrap; gap:10px; align-items:center;}
.user-pill {padding:8px 12px; border-radius:999px; background:var(--highlight); border:1px solid rgba(34,211,238,0.45); font-weight:600; font-size:14px;}
button, select, input {padding:10px 12px; border-radius:12px; background:#0b1222; color:var(--ink); border:1px solid var(--border); font-size:14px;}
button {cursor:pointer; font-weight:600; transition:all 0.2s ease;}
button:hover {transform:translateY(-1px); box-shadow:0 4px 12px rgba(0,0,0,0.3);}
button.primary {background:linear-gradient(180deg, rgba(34,211,238,0.18), rgba(34,211,238,0.06)); border-color:rgba(34,211,238,0.5);}
button.success {background:linear-gradient(180deg, rgba(16,185,129,0.2), rgba(16,185,129,0.08)); border-color:rgba(16,185,129,0.5);}
button.danger {background:linear-gradient(180deg, rgba(251,113,133,0.2), rgba(251,113,133,0.08)); border-color:rgba(251,113,133,0.55);}

/* Enhanced Grid Container with Horizontal Scroll Only */
.grid-container {margin: 20px 0;padding: 20px;background: rgba(255, 255, 255, 0.02);border: 1px dashed var(--border);border-radius: 12px;overflow: hidden;width: 100%;max-width: 100%;min-height: 200px;display: block;}
.crossword-grid-wrapper {overflow-x: auto;overflow-y: auto;-webkit-overflow-scrolling: touch;overscroll-behavior: contain;scrollbar-width: thin;scrollbar-color: var(--accent) rgba(255, 255, 255, 0.05);max-height: 400px;}
.crossword-grid-wrapper::-webkit-scrollbar {width: 8px;height: 8px;}
.crossword-grid-wrapper::-webkit-scrollbar-track {background: rgba(255, 255, 255, 0.05);border-radius: 4px;}
.crossword-grid-wrapper::-webkit-scrollbar-thumb {background: var(--accent);border-radius: 4px;}
.crossword-grid-wrapper::-webkit-scrollbar-thumb:hover {background: #1dd1db;}
.crossword-grid {display: grid;gap: 2px;padding: 15px;background: rgba(0, 0, 0, 0.2);border-radius: 8px;box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);max-width: fit-content;min-width: 100%;}
/* Enhanced Crossword Cells with Better Visibility */
.crossword-cell {position:relative; background:#ffffff; border:2px solid #ddd; border-radius:6px; display:flex; align-items:center; justify-content:center; transition:all 0.2s ease; overflow:visible;}
.crossword-cell.blocked {background:#000; border-color:#222;}
.crossword-cell.answered {background:#e0f7fa; border-color:var(--accent); box-shadow:0 0 8px rgba(34,211,238,0.3);}

/* Enhanced Input Fields with Better Mobile Support */
.crossword-cell input {width:100%; height:100%; border:none; background:transparent; text-align:center; font-weight:700; text-transform:uppercase; color:#000; border-radius:4px; outline:none; padding:0; margin:0; line-height:1; vertical-align:middle;}
.crossword-cell input:focus {background:rgba(34,211,238,0.1); box-shadow:inset 0 0 0 2px var(--accent);}
.crossword-cell input.highlighted {background:rgba(34,211,238,0.2); animation:pulse 1.5s infinite;}
.crossword-cell input:disabled {color:#333; cursor:not-allowed; background:rgba(16,185,129,0.1);}

@keyframes pulse {0%, 100% {background:rgba(34,211,238,0.2);} 50% {background:rgba(34,211,238,0.35);}}

.cell-number {position:absolute; top:1px; left:2px; font-weight:700; color:#000; z-index:2; background:rgba(255,255,255,0.95); border-radius:3px; box-shadow:0 1px 3px rgba(0,0,0,0.3); min-width:16px; text-align:center; line-height:1.2;}
.clues-wrap {margin-bottom:25px; display:grid; grid-template-columns:1fr 1fr; gap:20px;}
.clues-section {background:rgba(255,255,255,0.02); padding:18px; border-radius:12px; border:1px solid var(--border);}
.clue-item {padding:12px 15px; margin:6px 0; border-radius:8px; font-size:14px; line-height:1.4; transition:all 0.3s ease; border:1px solid transparent;}
.clue-item.selectable {cursor:pointer; background:rgba(255,255,255,0.03); border-color:rgba(255,255,255,0.1);}
.clue-item.selectable:hover {background:var(--highlight); border-color:rgba(34,211,238,0.4); transform:translateX(6px); box-shadow:0 4px 12px rgba(34,211,238,0.2);}
.clue-item.claimed {color:var(--muted); background:rgba(255,255,255,0.01); border-color:rgba(255,255,255,0.05); cursor:not-allowed; opacity:0.5; text-decoration:line-through;}
.status {margin-top:15px; color:var(--muted); font-size:14px; padding:12px; background:rgba(255,255,255,0.02); border-radius:8px; border:1px solid var(--border);}
.game-instructions {margin:20px 0; padding:16px; background:linear-gradient(135deg, rgba(34,211,238,0.05), rgba(16,185,129,0.05)); border:1px solid rgba(34,211,238,0.2); border-radius:12px; border-left:4px solid var(--accent);}
.game-instructions .hint {color:var(--ink); font-size:14px;}
.chat-card {display:flex; flex-direction:column; height:600px; min-height:400px; max-height:80vh; background:var(--light-bg); border-radius:12px; padding:16px;}
.chat-window {flex:1; min-height:0; overflow-y:auto; padding:12px; background:rgba(255,255,255,0.02); border-radius:8px; margin-bottom:12px; display:flex; flex-direction:column; gap:8px; -webkit-overflow-scrolling:touch;}
.chat-message {padding:10px 14px; border-radius:12px; font-size:14px; max-width:85%; line-height:1.5; border:1px solid transparent; display:flex; flex-wrap:wrap; gap:4px;}
.chat-message strong {font-weight:700; color:var(--ink); margin-right:6px;}
.chat-message.admin {background:rgba(34,211,238,0.15); border-color:rgba(34,211,238,0.3); align-self:flex-start;}
.chat-message.user {background:rgba(16,185,129,0.15); border-color:rgba(16,185,129,0.3); align-self:flex-end;}
.chat-bubble {width:100%;}
.chat-sender {width:100%; word-break:break-word;}
.chat-input {display:flex; gap:10px;}
.chat-input input {flex:1; padding:12px; border-radius:20px; border:1px solid var(--border); background:rgba(255,255,255,0.05); color:var(--ink);}
.btn {background:var(--accent); color:var(--ink); border:none; font-weight:600; border-radius:20px; padding:12px 20px; transition:all 0.2s ease;}
.table {width:100%; border-collapse:collapse;}
.table th, .table td {text-align:left; padding:10px 12px; border-bottom:1px solid var(--border);}
.table th {font-size:12px; text-transform:uppercase; letter-spacing:.5px; color:var(--muted); font-weight:600;}
.status-online {color:var(--success); font-weight:600; font-size:0.85em;}
.status-offline {color:var(--danger); font-weight:600; font-size:0.85em;}
.muted {color:var(--muted);}
.popup-overlay {position:fixed; top:0; left:0; width:100vw; height:100vh; background:rgba(0,0,0,0.8); display:flex; justify-content:center; align-items:center; z-index:9999; opacity:0; visibility:hidden; transition:all 0.3s ease; backdrop-filter:blur(5px);}
.popup-overlay.show {opacity:1; visibility:visible;}
.popup {background:var(--light-bg); border:2px solid var(--border); border-radius:20px; padding:30px; max-width:90vw; width:400px; text-align:center; box-shadow:0 20px 60px rgba(0,0,0,0.7); transform:scale(0.8) translateY(20px); transition:all 0.3s ease; backdrop-filter:blur(15px);}
.popup-overlay.show .popup {transform:scale(1) translateY(0);}
.popup.success {border-color:var(--success); background:linear-gradient(135deg, rgba(16,185,129,0.15), var(--light-bg));}
.popup.error {border-color:var(--danger); background:linear-gradient(135deg, rgba(251,113,133,0.15), var(--light-bg));}
.popup-icon {font-size:60px; margin-bottom:15px; display:block; animation:bounceIn 0.5s ease;}
.popup h3 {margin:10px 0; font-size:24px; color:var(--ink);}
.popup p {margin:10px 0 20px; color:var(--muted); line-height:1.5; font-size:16px;}
.popup-close {background:var(--accent); color:var(--bg); border:none; padding:12px 25px; border-radius:25px; font-weight:600; cursor:pointer; transition:all 0.2s ease;}
.popup-close:hover {background:#1dd1db; transform:translateY(-2px);}

/* Auth Page Styles */
.auth-wrap {display: flex;justify-content: center;align-items: center;min-height: 100vh;padding: 20px;background: radial-gradient(1200px 800px at 50% 50%, #0b1222 0%, var(--bg) 40%, #0b1222 100%);}
.auth-card {width: 100%;max-width: 420px;margin: 0 auto;text-align: center;background: var(--light-bg);border: 1px solid var(--border);border-radius: 16px;padding: 32px;box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);backdrop-filter: blur(10px);}
.auth-header {margin-bottom: 24px;}
.auth-header h1 {font-size: 32px;font-weight: 700;color: var(--ink);margin: 0 0 8px;}
.auth-header .subtitle {font-size: 16px;color: var(--muted);margin: 0 0 12px;}
.auth-header small {font-size: 12px;color: var(--muted);}
.auth-form {display: flex;flex-direction: column;gap: 20px;}
.auth-form label {display: flex;flex-direction: column;gap: 8px;text-align: left;font-size: 14px;font-weight: 500;color: var(--ink);}
.auth-form input {width: 100%;padding: 12px 16px;border-radius: 12px;background: rgba(255, 255, 255, 0.05);border: 1px solid var(--border);color: var(--ink);font-size: 16px;transition: all 0.2s ease;}
.auth-form input:focus {border-color: var(--accent);box-shadow: 0 0 0 3px var(--highlight);outline: none;}
.auth-form input::placeholder {color: var(--muted);opacity: 0.7;}
.auth-form .flex {display: flex;gap: 16px;margin-top: 12px;}
.auth-form .flex button {flex: 1;padding: 12px 16px;font-size: 16px;font-weight: 600;border-radius: 12px;transition: all 0.2s ease;}
.auth-form .flex button.primary {background: linear-gradient(180deg, rgba(34, 211, 238, 0.18), rgba(34, 211, 238, 0.06));border-color: rgba(34, 211, 238, 0.5);}
.auth-form .flex button.primary:hover {background: linear-gradient(180deg, rgba(34, 211, 238, 0.24), rgba(34, 211, 238, 0.12));transform: translateY(-2px);box-shadow: 0 4px 12px rgba(34, 211, 238, 0.3);}
.auth-form .flex button:not(.primary) {background: rgba(255, 255, 255, 0.05);border: 1px solid var(--border);}
.auth-form .flex button:not(.primary):hover {background: rgba(255, 255, 255, 0.1);transform: translateY(-2px);box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);}
small {font-size: 12px;color: var(--muted);font-weight: 400;}
code {background: rgba(255, 255, 255, 0.1);padding: 2px 6px;border-radius: 4px;font-family: monospace;color: var(--accent);}

/* Responsive Design - Desktop First */
@media (max-width: 1024px) {
  .app {grid-template-columns:1fr;}
  body {padding:0;}
  .clues-wrap {grid-template-columns:1fr; gap:15px;}
  .grid-container {min-height:180px;}
}

/* Tablet Landscape - 768px to 1024px */
@media (max-width: 768px) {
  .app-container {padding:10px;}
  .app {grid-template-columns: 1fr;width: 100%;max-width: 100vw;}
  .card {padding:15px;}
  .crossword-cell {width:30px; height:30px;}
  .crossword-cell input {font-size:16px;}
  .cell-number {font-size:8px; top:0px; left:1px; padding:1px 3px;}
  .crossword-grid {padding:12px; gap:1.5px;}
  .crossword-grid-wrapper {max-height: 800px;}
  h1 {font-size:22px;}
  .header {flex-direction:column; align-items:stretch; gap:15px;}
  .toolbar {justify-content:center;}
  .chat-card {height:300px;}
  .popup {padding:25px; margin:15px; max-width:85vw;}
  .popup h3 {font-size:20px;}
  .popup-icon {font-size:50px;}
}

/* Mobile Portrait - 481px to 768px */
@media (max-width: 480px) {
  .app-container {padding:8px;}
  .app {max-width: 100vw;}
  .card {padding:12px;}
  .crossword-cell {width:28px; height:28px;}
  .crossword-cell input {font-size:16px; font-weight:700;}
  .cell-number {font-size:7px; top:0px; left:0px; padding:1px 2px; min-width:12px;}
  .crossword-grid {padding:10px; gap:1.5px;}
  .crossword-grid-wrapper {max-height: 600px;}
  .grid-container {padding:10px; min-height:160px;}
  h1 {font-size:18px;}
  .clue-item {font-size:12px; padding:10px 12px;}
  .game-instructions .hint {font-size:12px;}
  button, select, input {font-size:12px; padding:8px 10px;}
  .user-pill {font-size:12px; padding:6px 10px;}
  .chat-card {height:250px;}
  .popup {padding:20px; margin:10px; max-width:90vw;}
  .popup h3 {font-size:18px;}
  .popup p {font-size:14px;}
  .popup-icon {font-size:40px;}
  .auth-card {padding:24px; max-width:90vw;}
  .auth-header h1 {font-size:28px;}
  .auth-form input {font-size:14px; padding:10px 14px;}
  .auth-form .flex button {font-size:14px; padding:10px 14px;}
}

/* Small Mobile - 361px to 480px */
@media (max-width: 360px) {
  .app-container {padding:6px;}
  .crossword-cell {width:26px; height:26px;}
  .crossword-cell input {font-size:16px; font-weight:700;}
  .cell-number {font-size:6px; padding:0px 1px; min-width:10px;}
  .crossword-grid {padding:8px;}
  .crossword-grid-wrapper {max-height: 400px;}
  .grid-container {padding:8px; min-height:140px;}
  h1 {font-size:16px;}
  .clue-item {font-size:11px; padding:8px 10px;}
  .auth-card {padding:20px;}
  .auth-header h1 {font-size:24px;}
  .auth-header .subtitle {font-size:14px;}
  .auth-form input {font-size:13px; padding:8px 12px;}
  .auth-form .flex button {font-size:13px; padding:8px 12px;}
}

/* Extra Small Mobile - up to 360px */
@media (max-width: 320px) {
  .crossword-cell {width:24px; height:24px;}
  .crossword-cell input {font-size:16px;}
  .cell-number {font-size:5px; padding:0px; min-width:8px;}
  .crossword-grid-wrapper {max-height:180px;}
  .grid-container {min-height:120px;}
  .popup {padding:12px; margin:3px;}
  .popup h3 {font-size:14px;}
  .popup-icon {font-size:30px;}
}

/* Landscape Orientation Adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  .app {grid-template-columns:1.5fr 1fr;}
  .chat-card {height:200px;}
  .grid-container {min-height:120px;}
  .crossword-grid-wrapper {max-height:150px;}
  .popup {max-height:80vh; overflow-y:auto;}
}

/* High DPI Display Support */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx) {
  .crossword-cell {border-width:1px;}
  .cell-number {box-shadow:0 0.5px 1.5px rgba(0,0,0,0.3);}
}

/* MOBILE KEYBOARD FIX */
.keyboard-open {position:fixed !important; width:100% !important; height:100% !important; overflow:hidden !important;}
@media (max-width: 768px) {
  .crossword-cell input {font-size:16px !important; -webkit-text-size-adjust:100%; -webkit-appearance:none; -webkit-tap-highlight-color:transparent; transform:translateZ(0);}
  .crossword-cell input:focus {outline:none; -webkit-tap-highlight-color:transparent; -webkit-user-select:auto; user-select:auto;}
  .crossword-cell {-webkit-tap-highlight-color:transparent; touch-action:manipulation;}
  .crossword-cell input.highlighted {transition:background-color 0.3s ease;}
  .crossword-grid {-webkit-user-select:none; user-select:none; -webkit-touch-callout:none;}
  .crossword-cell input {-webkit-user-select:auto; user-select:auto;}
  html {-webkit-text-size-adjust:100%; -ms-text-size-adjust:100%;}
  body {-webkit-overflow-scrolling:touch; overscroll-behavior:none;}
  .crossword-grid-wrapper {-webkit-overflow-scrolling:touch; overscroll-behavior-x:contain;}
  .popup-overlay {position:fixed; z-index:99999; -webkit-overflow-scrolling:touch;}
  .popup-overlay.show .popup {max-height:70vh; overflow-y:auto; -webkit-overflow-scrolling:touch;}
}
@media (max-width: 480px) {
  .crossword-cell input {font-size:16px !important; line-height:1.2; padding:0; margin:0;}
  .crossword-cell {min-width:28px; min-height:28px;}
}
@media (max-width: 360px) {
  .crossword-cell input {font-size:16px !important; font-weight:600;}
  .crossword-cell {min-width:26px; min-height:26px;}
}
@supports (-webkit-touch-callout: none) {
  .crossword-cell input {-webkit-appearance:none; border-radius:0;}
  .crossword-cell input:focus {-webkit-appearance:none; outline:none;}
}
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  .crossword-cell input {background-clip:padding-box;}
}
@media (max-height: 500px) and (orientation: landscape) {
  .keyboard-open {position:static !important; height:auto !important;}
  .grid-container {min-height:100px;}
  .crossword-grid-wrapper {max-height:100px;}
  .popup {max-height:60vh; margin:10px;}
}