* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}
:root {
    --bg-primary: #f2f2f7;
    --bg-chat: #ffffff;
    --bubble-self: #0a84ff;
    --bubble-other: #e9e9ed;
    --text-primary: #1c1c1e;
    --text-secondary: #8e8e93;
    --nav-blur: rgba(242, 242, 247, 0.85);
    --shadow-md: 0 8px 30px rgba(0,0,0,0.08);
    --radius-bubble: 18px;
    --radius-input: 28px;
    --safe-top: env(safe-area-inset-top, 20px);
    --safe-bottom: env(safe-area-inset-bottom, 10px);
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: var(--text-primary);
}
#navBar {
    background: var(--nav-blur);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid rgba(0,0,0,0.08);
    padding: 12px 16px 8px;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 56px;
    padding-top: calc(12px + var(--safe-top));
}
.nav-left {
    display: flex;
    flex-direction: column;
}
.nav-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text-primary);
    line-height: 1.2;
}
.nav-subtitle {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
    letter-spacing: 0.2px;
}
.nav-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.nav-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}
.nav-status .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #34c759;
    transition: all 0.3s ease;
}
.nav-status .dot.offline {
    background: #ff3b30;
    opacity: 0.5;
}
.nav-status .dot.waiting {
    background: #ff9500;
    animation: pulse-dot 1.5s ease-in-out infinite;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.8); }
}
.nav-badge {
    background: var(--bubble-self);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 12px;
    border-radius: 20px;
    letter-spacing: 0.3px;
}
#landing {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px;
    background: linear-gradient(145deg, #f2f2f7 0%, #e5e5ea 100%);
}
#landing h1 {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
    color: var(--text-primary);
}
#landing .subhead {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}
#landing .card {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(180%) blur(30px);
    -webkit-backdrop-filter: saturate(180%) blur(30px);
    border-radius: 28px;
    padding: 28px 24px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-md), 0 0 0 0.5px rgba(0,0,0,0.02);
    display: flex;
    flex-direction: column;
    gap: 18px;
    border: 0.5px solid rgba(255,255,255,0.6);
    transition: all 0.3s ease;
}
#landing .card .waiting-area {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
#landing .card .waiting-area .room-code-box {
    background: var(--bg-primary);
    border-radius: 16px;
    padding: 14px;
    width: 100%;
    text-align: center;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 4px;
    color: var(--bubble-self);
    border: 1px dashed var(--bubble-self);
}
#landing .card .waiting-area .waiting-hint {
    font-size: 15px;
    color: var(--text-secondary);
}
#landing .card .waiting-area .action-row {
    display: flex;
    gap: 12px;
    width: 100%;
}
#landing .card .waiting-area .action-row button {
    flex: 1;
    padding: 14px 10px;
    border: none;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
#landing .card .waiting-area .action-row button:active {
    transform: scale(0.96);
    opacity: 0.7;
}
.btn-copy {
    background: rgba(0,0,0,0.05);
    color: var(--text-primary);
}
.btn-wait {
    background: var(--bubble-self);
    color: white;
    box-shadow: 0 4px 12px rgba(10,132,255,0.3);
}
#landing .card .input-group {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
#landing .card .input-group input {
    padding: 16px 18px;
    border-radius: 16px;
    border: 1.5px solid rgba(0,0,0,0.06);
    background: rgba(255,255,255,0.8);
    font-size: 18px;
    text-align: center;
    outline: none;
    transition: border 0.2s;
    font-weight: 500;
    letter-spacing: 4px;
}
#landing .card .input-group input:focus {
    border-color: var(--bubble-self);
    background: white;
}
#landing .card .btn-group {
    display: flex;
    gap: 12px;
}
#landing .card button {
    flex: 1;
    padding: 16px 12px;
    border: none;
    border-radius: 18px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.5px rgba(0,0,0,0.02);
}
#landing .card button:active {
    transform: scale(0.96);
    opacity: 0.7;
}
.btn-create {
    background: var(--bubble-self) !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(10,132,255,0.3) !important;
}
.btn-join {
    background: #34c759 !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(52,199,89,0.3) !important;
}
#landing .hint {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 4px;
}
#chatContainer {
    flex: 1;
    display: none;
    flex-direction: column;
    background: var(--bg-chat);
    overflow: hidden;
    position: relative;
}
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
    background: #f8f8fc;
    background-image: radial-gradient(circle at 20% 30%, rgba(10,132,255,0.02) 0%, transparent 50%);
}
.message {
    max-width: 76%;
    padding: 10px 16px;
    border-radius: var(--radius-bubble);
    word-wrap: break-word;
    font-size: 16px;
    line-height: 1.45;
    position: relative;
    clear: both;
    animation: msg-pop 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    margin-bottom: 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}
@keyframes msg-pop {
    0% { opacity: 0; transform: scale(0.92) translateY(8px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}
.message.self {
    align-self: flex-end;
    background: var(--bubble-self);
    color: white;
}
.message.other {
    align-self: flex-start;
    background: var(--bubble-other);
    color: var(--text-primary);
}
.message.system {
    align-self: center;
    background: rgba(0,0,0,0.04);
    color: var(--text-secondary);
    font-size: 13px;
    padding: 6px 16px;
    border-radius: 30px;
    max-width: 90%;
    backdrop-filter: blur(4px);
    border: 0.5px solid rgba(0,0,0,0.02);
}
#inputArea {
    display: flex;
    align-items: center;
    padding: 10px 16px calc(10px + var(--safe-bottom));
    background: rgba(248,248,252,0.92);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 0.5px solid rgba(0,0,0,0.06);
    gap: 8px;
    flex-shrink: 0;
}
#inputArea #msgInput {
    flex: 1;
    border: none;
    border-radius: var(--radius-input);
    padding: 10px 18px;
    font-size: 16px;
    background: rgba(0,0,0,0.04);
    outline: none;
    min-height: 40px;
    max-height: 120px;
    transition: background 0.2s, box-shadow 0.2s;
}
#inputArea #msgInput:focus {
    background: white;
    box-shadow: 0 0 0 2px rgba(10,132,255,0.2);
}
#inputArea #sendBtn {
    background: var(--bubble-self);
    border: none;
    color: white;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(10,132,255,0.25);
    flex-shrink: 0;
    padding: 0;
}
#inputArea #sendBtn:active {
    transform: scale(0.88);
    opacity: 0.8;
}
#inputArea #sendBtn:disabled {
    opacity: 0.3;
    transform: scale(1);
    box-shadow: none;
    cursor: default;
}
#inputArea #sendBtn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
    display: block;
}
@media (orientation: landscape) and (max-height: 500px) {
    .message { max-width: 60%; font-size: 15px; padding: 6px 14px; }
    #inputArea { padding: 6px 12px; min-height: 44px; }
    #inputArea #msgInput { padding: 6px 14px; font-size: 14px; min-height: 32px; }
    #inputArea #sendBtn { width: 36px; height: 36px; }
    #inputArea #sendBtn svg { width: 18px; height: 18px; }
    #navBar { padding: 4px 16px; min-height: 40px; }
    .nav-title { font-size: 16px; }
    #landing h1 { font-size: 24px; }
    #landing .card { padding: 20px; gap: 12px; }
}
@media (max-width: 400px) {
    .message { font-size: 15px; padding: 8px 12px; }
    #landing .card { padding: 20px; }
    #landing .card input { font-size: 16px; padding: 14px; }
}
#messages::-webkit-scrollbar { width: 3px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 10px; }