:root {
    --primary: #4CAF50;
    --primary-dark: #43A047;
    --danger: #f44336;
    --warning: #FF9800;
    --bg: #f5f5f5;
    --card: #ffffff;
    --text: #333333;
    --text-light: #999999;
    --border: #eeeeee;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 12px;
    --radius-sm: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    min-height: 100vh;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
}

.page {
    min-height: 100vh;
}

/* ===== Login Page ===== */
.page-login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.login-card {
    width: 100%;
    background: var(--card);
    border-radius: var(--radius);
    padding: 40px 24px;
    box-shadow: var(--shadow);
    text-align: center;
}

.app-title {
    font-size: 32px;
    margin-bottom: 8px;
}

.app-subtitle {
    color: var(--text-light);
    margin-bottom: 32px;
    font-size: 14px;
}

/* ===== Form Elements ===== */
.form-group {
    margin-bottom: 16px;
}

.input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    background: #fafafa;
    -webkit-appearance: none;
}

.input:focus {
    border-color: var(--primary);
    background: #fff;
}

.input::placeholder {
    color: #bbb;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-appearance: none;
    touch-action: manipulation;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}

.btn-outline:hover {
    background: rgba(76, 175, 80, 0.05);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
}

/* ===== Lobby Page ===== */
.page-lobby {
    padding: 0;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar-small {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.username {
    font-weight: 600;
    font-size: 16px;
}

.lobby-content {
    padding: 24px 20px;
}

.lobby-section {
    margin-bottom: 24px;
}

.lobby-section h2 {
    font-size: 16px;
    color: var(--text-light);
    margin-bottom: 12px;
    font-weight: 500;
}

.lobby-divider {
    text-align: center;
    color: var(--text-light);
    font-size: 14px;
    margin: 20px 0;
    position: relative;
}

.lobby-divider::before,
.lobby-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: var(--border);
}

.lobby-divider::before { left: 0; }
.lobby-divider::after { right: 0; }

.join-form {
    display: flex;
    gap: 10px;
}

.join-form .input {
    flex: 1;
}

.join-form .btn {
    flex-shrink: 0;
}

.current-room-section {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.current-room-card {
    text-align: center;
    cursor: pointer;
}

.room-code-display {
    font-size: 36px;
    font-weight: 800;
    letter-spacing: 8px;
    color: var(--primary);
    margin-bottom: 4px;
}

.room-info-text {
    color: var(--text-light);
    font-size: 13px;
}

/* ===== Room Page ===== */
.page-room {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.room-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.room-code-badge {
    font-size: 15px;
    font-weight: 700;
    color: var(--primary);
    background: rgba(76, 175, 80, 0.1);
    padding: 4px 14px;
    border-radius: 20px;
}

/* ===== Members Bar ===== */
.members-bar {
    display: flex;
    gap: 12px;
    padding: 16px;
    overflow-x: auto;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
}

.members-bar::-webkit-scrollbar {
    display: none;
}

.member-avatar-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    min-width: 84px;
}

.avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 30px;
    transition: transform 0.2s;
}

.member-avatar-wrapper:active .avatar {
    transform: scale(0.9);
}

.avatar-tea {
    background: #FFF3E0;
    font-size: 33px;
}

.member-name {
    font-size: 16.5px;
    color: var(--text-light);
    max-width: 84px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.me-badge {
    position: absolute;
    top: 2px;
    right: 6px;
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 8px;
    font-weight: 600;
}

.member-balance {
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
}

.balance-positive {
    color: var(--danger);
}

.balance-negative {
    color: var(--primary);
}

.tea-fee-amount {
    color: #FF9800;
    font-weight: 600;
}

.tea-fee-members {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.tea-fee-member-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-card);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
}

.tea-fee-member-item:active {
    background: #e0e0e0;
}

/* ===== Records List ===== */
.records-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    -webkit-overflow-scrolling: touch;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
    font-size: 14px;
}

.record-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--card);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: background 0.15s;
    -webkit-user-select: none;
    user-select: none;
}

.record-item:active {
    background: #f0f0f0;
}

.record-item.recalled {
    opacity: 0.5;
    background: #fafafa;
}

.record-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.record-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
}

.record-info {
    flex: 1;
    min-width: 0;
}

.record-names {
    font-size: 15px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.record-names .arrow {
    color: var(--primary);
    margin: 0 6px;
    font-weight: 700;
}

.record-time {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 2px;
}

.record-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.record-amount {
    font-size: 18px;
    font-weight: 700;
}

.record-positive {
    color: var(--danger);
}

.record-negative {
    color: var(--primary);
}

.tea-amount {
    color: var(--warning);
}

.tea-label {
    font-size: 11px;
    background: #FFF3E0;
    color: var(--warning);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.recalled-label {
    font-size: 11px;
    background: #FFF3E0;
    color: var(--warning);
    padding: 2px 6px;
    border-radius: 4px;
}

/* ===== Modals ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--card);
    border-radius: var(--radius);
    width: 100%;
    max-width: 360px;
    overflow: hidden;
    animation: slideUp 0.25s;
}

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

.modal-summary {
    max-width: 420px;
}

.modal-header {
    padding: 20px 24px 0;
    font-size: 18px;
    font-weight: 700;
}

.modal-body {
    padding: 20px 24px;
}

.modal-desc {
    color: var(--text-light);
    font-size: 14px;
    margin-bottom: 16px;
}

.modal-footer {
    display: flex;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

.modal-footer .btn {
    flex: 1;
}

.score-target-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 28px;
    margin: 0 auto 16px;
}

.recall-detail {
    margin-top: 12px;
    padding: 12px;
    background: #f5f5f5;
    border-radius: var(--radius-sm);
    font-size: 15px;
    text-align: center;
}

.recall-detail span {
    margin: 0 4px;
}

/* ===== Summary ===== */
.summary-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.summary-item:last-child {
    border-bottom: none;
}

.summary-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    min-width: 80px;
}

.summary-amounts {
    display: flex;
    gap: 12px;
    font-size: 13px;
    color: var(--text-light);
}

.summary-amounts .paid { color: var(--danger); }
.summary-amounts .received { color: var(--primary); }
.summary-amounts .tea-fee { color: var(--warning); }

.summary-net {
    font-weight: 700;
    font-size: 16px;
    min-width: 70px;
    text-align: right;
}

.summary-net.positive { color: var(--primary); }
.summary-net.negative { color: var(--danger); }

/* ===== Responsive ===== */
@media (min-width: 481px) {
    .app-container {
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
        box-shadow: 0 0 20px rgba(0,0,0,0.05);
    }
}

@media (max-width: 360px) {
    .app-title { font-size: 26px; }
    .room-code-display { font-size: 28px; letter-spacing: 4px; }
    .avatar { width: 40px; height: 40px; font-size: 17px; }
    .member-name { font-size: 10px; }
    .record-amount { font-size: 16px; }
}
