:root {
    --bg: #f4f1ea;
    --panel: #ffffff;
    --ink: #232323;
    --muted: #6b6b6b;
    --accent: #2f6f4e;
    --danger: #a33b32;
    --border: #d8d2c6;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
}

a {
    color: var(--accent);
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    background: var(--ink);
    color: #fff;
}

.topbar a {
    color: #fff;
    text-decoration: none;
}

.brand {
    font-weight: 700;
    letter-spacing: 0.02em;
}

.topnav {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.username {
    opacity: 0.7;
}

.inline-form {
    display: inline;
    margin: 0;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.link-button {
    background: none;
    border: 0;
    color: #fff;
    cursor: pointer;
    padding: 0;
    font: inherit;
}

.page {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.25rem;
}

.page-room {
    max-width: 1440px;
    padding: clamp(0.65rem, 1.2vw, 1.25rem);
}

.messages {
    list-style: none;
    max-width: 960px;
    margin: 1rem auto 0;
    padding: 0 1.25rem;
}

.message {
    padding: 0.6rem 0.9rem;
    border-radius: 6px;
    background: #e7f0e9;
    border: 1px solid #bfd4c5;
    margin-bottom: 0.5rem;
}

.message.error {
    background: #f6e4e2;
    border-color: #dfb3ae;
}

h1 {
    margin-top: 0;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

.row-form {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.9rem;
}

select,
input,
button {
    font: inherit;
    padding: 0.5rem 0.7rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #fff;
}

button {
    cursor: pointer;
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button.danger {
    background: var(--danger);
    border-color: var(--danger);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.stack p {
    margin: 0 0 0.6rem;
}

.friends-select {
    padding-top: 0.5rem;
}

.friends-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.checkbox {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.25rem 0.7rem;
}

.checkbox input {
    width: auto;
}

.stack input {
    width: 100%;
    max-width: 360px;
}

.room-table {
    width: 100%;
    border-collapse: collapse;
}

.room-table th,
.room-table td {
    text-align: left;
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.room-table .actions {
    display: grid;
    grid-template-columns: repeat(3, 2.15rem);
    align-items: center;
    justify-content: start;
    gap: 0.35rem;
}

.room-table .actions form {
    display: flex;
    margin: 0;
}

.room-table .actions .icon-button {
    width: 2.15rem;
    height: 2.15rem;
    padding: 0;
}

.room-table .actions .icon-button.is-disabled,
.room-table .actions .icon-button:disabled {
    opacity: 0.35;
    pointer-events: none;
}

.actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.button {
    display: inline-block;
    padding: 0.35rem 0.7rem;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
}

.muted {
    color: var(--muted);
}

.room-header {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-start;
    justify-content: space-between;
}

.room-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.participants {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.participants li {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.35rem 0.75rem;
}

.participants .role {
    color: var(--muted);
    font-size: 0.85rem;
}

.color-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.05rem 0.35rem;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.04);
    font-size: 0.85rem;
}

.color-dot {
    display: inline-block;
    flex: none;
    width: 0.8rem;
    height: 0.8rem;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.2);
}

.color-dot.color-W {
    background: #ffffff;
}

.color-dot.color-Y {
    background: #f2c94c;
}

.color-dot.color-G {
    background: #56c271;
}

.color-dot.color-R {
    background: #e05a5a;
}

.join-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: flex-end;
}

.inline-label {
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
}

.rematch-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.toggle {
    background: #fff;
    color: var(--accent);
    border-color: var(--accent);
}

.toggle.is-active {
    background: var(--accent);
    color: #fff;
}

.badge-ready {
    background: #2f6f4e;
}

.badge {
    background: var(--ink);
    color: #fff;
    border-radius: 999px;
    padding: 0.1rem 0.5rem;
    font-size: 0.75rem;
}

.invite {
    margin-bottom: 0;
    word-break: break-all;
}

.game-panel {
    min-height: 160px;
}

.error {
    background: #f6e4e2;
    border: 1px solid #dfb3ae;
    color: var(--danger);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.high-card-game {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.high-card-status {
    font-weight: 600;
}

.high-card-players {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0;
    margin: 0;
}

.high-card-players li {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    align-items: center;
    min-width: 120px;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #faf8f3;
}

.high-card-players li.is-turn {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(47, 111, 78, 0.2);
}

.high-card-players .card {
    font-size: 1.6rem;
    font-weight: 700;
}

.high-card-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}


.user-menu {
    position: relative;
}

.user-menu summary {
    cursor: pointer;
    list-style: none;
}

.user-menu summary::-webkit-details-marker {
    display: none;
}

.user-menu summary::after {
    content: " ▾";
    font-size: 0.75rem;
    opacity: 0.7;
}

.user-menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.5rem);
    z-index: 20;
    display: flex;
    min-width: 11rem;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.user-menu-panel a,
.user-menu-panel .link-button {
    display: block;
    padding: 0.35rem 0.5rem;
    border-radius: 5px;
    color: var(--ink);
    text-align: left;
    text-decoration: none;
}

.user-menu-panel a:hover,
.user-menu-panel .link-button:hover {
    background: #f1ede5;
}

.profile-actions,
.relation-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.relation-actions form {
    display: inline;
    margin: 0;
}

.secondary-actions {
    margin-top: 0.75rem;
}

.button.secondary {
    background: #fff;
    color: var(--accent);
    border: 1px solid var(--accent);
}

.country-flag {
    font-size: 0.95em;
    line-height: 1;
}

.preserve-lines {
    white-space: pre-line;
}

.search-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}

.search-results {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}

.user-card {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-start;
    justify-content: space-between;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
}

.user-card-main {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 12rem;
}

.user-card-name {
    font-weight: 600;
}

.user-card-bio {
    white-space: pre-line;
}

.notification-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.notification-list li {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.65rem 0.75rem;
}

.notification-list li.unread {
    border-color: var(--accent);
    background: #f3f8f4;
}

.note-card {
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 0;
}

.note-card:last-child {
    border-bottom: 0;
}

.note-text {
    white-space: pre-line;
}

@media (max-width: 600px) {
    .page {
        padding: 0.75rem;
    }

    .room-table {
        display: block;
        overflow-x: auto;
    }
}

.profile-header {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.profile-summary {
    flex: 1;
    min-width: 180px;
}

.profile-summary h1 {
    margin-bottom: 0.25rem;
}

.profile-summary p {
    margin: 0;
}

.profile-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.profile-actions form {
    margin: 0;
}

.avatar-large {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 4.5rem;
    height: 4.5rem;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 2rem;
    font-weight: 700;
}

.detail-list {
    display: grid;
    gap: 0.5rem;
    margin: 0;
}

.detail-list div {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.detail-list dt {
    color: var(--muted);
}

.detail-list dd {
    margin: 0;
}

.user-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0;
    margin: 0 0 1rem;
}

.user-list li {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 999px;
}

/* Profile menu */
.user-menu-panel {
    width: max-content;
    min-width: 12rem;
    max-width: min(18rem, calc(100vw - 2rem));
    gap: 0.15rem;
    overflow-wrap: anywhere;
}

.user-menu-panel > * {
    width: 100%;
}

.user-menu-panel a,
.user-menu-panel .link-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.user-menu-panel form {
    margin: 0;
}

/* Room layout */
.room-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 280px);
    grid-template-areas:
        "board summary"
        "board side";
    grid-template-rows: auto minmax(0, 1fr);
    gap: 1rem;
    align-items: stretch;
}

.room-main {
    grid-area: board;
}

.room-summary {
    align-self: start;
    grid-area: summary;
}

.room-side {
    display: flex;
    flex-direction: column;
    grid-area: side;
    min-height: 0;
    max-height: 100%;
    gap: 0.75rem;
    overflow: hidden;
    contain: size;
}

.room-side > .panel {
    margin-bottom: 0;
    padding: 0.75rem 0.9rem;
}

.participants-panel {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.participants-panel h2 {
    margin-bottom: 0.5rem;
}

.participants-panel .participants {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.room-main,
.room-summary,
.room-side {
    min-width: 0;
}

.room-summary,
.room-main > .panel,
.room-side > .panel:last-child {
    margin-bottom: 0;
}

.room-summary h1 {
    margin-bottom: 0.4rem;
    font-size: clamp(1.35rem, 2vw, 1.7rem);
    line-height: 1.15;
}

.room-meta {
    display: grid;
    gap: 0.1rem;
}

.room-meta p {
    margin: 0;
}

.room-status {
    font-weight: 600;
}

.room-host {
    font-size: 0.9rem;
}

.room-invite {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.room-summary .room-invite {
    flex-direction: column;
    align-items: stretch;
}

.room-summary .invite-copy {
    justify-content: center;
}

.room-summary .copy-status {
    text-align: center;
}

.invite-copy {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.copy-status {
    min-height: 1em;
    color: var(--accent);
    font-size: 0.85rem;
}

.room-actions {
    flex-direction: column;
    align-items: stretch;
}

.room-actions form,
.room-actions button,
.room-actions .button {
    width: 100%;
}

.room-actions .join-form {
    flex-direction: column;
    align-items: stretch;
}

.room-actions .inline-label {
    justify-content: space-between;
}

.room-side h2,
.room-controls h2 {
    margin-top: 0;
    font-size: 1.05rem;
}

.game-panel {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
    padding: clamp(0.65rem, 1vw, 1rem);
}

.game-panel #game-container {
    display: flex;
    justify-content: center;
    width: 100%;
    min-width: 0;
}

.game-waiting {
    margin: 0;
    color: var(--muted);
    text-align: center;
}

/* Participants */
.participants {
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0.3rem;
}

.participants li {
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.3rem;
    padding: 0.3rem 0.45rem;
    border-radius: 8px;
}

.participants li.is-turn {
    border-color: var(--accent);
    box-shadow: inset 3px 0 0 var(--accent);
}

.participant-main {
    display: flex;
    flex: 1 1 0;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.35rem;
    min-width: 0;
}

.participants .name {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.participants .role {
    font-size: 0.78rem;
    white-space: nowrap;
}

.participants .color-chip {
    padding: 0 0.3rem;
    font-size: 0.78rem;
}

.participant-color-form {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.participant-color-form select {
    max-width: 7rem;
    padding: 0.2rem 0.3rem;
}

.turn-dot {
    display: inline-block;
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(47, 111, 78, 0.2);
}

/* Icons */
.icon,
.action-icon {
    width: 1.1rem;
    height: 1.1rem;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

.relation-actions:not(.icon-actions) .action-icon {
    display: none;
}

.relation-actions.icon-actions {
    flex-wrap: nowrap;
    gap: 0.2rem;
}

.relation-actions.icon-actions .icon-button,
.participant-color-form .icon-button,
.button.icon-button {
    width: 2.15rem;
    height: 2.15rem;
    padding: 0;
}

.participants .relation-actions.icon-actions .icon-button {
    width: 1.9rem;
    height: 1.9rem;
}

.relation-actions.icon-actions .action-label {
    display: none;
}

@media (max-width: 760px) {
    .room-layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "summary"
            "board"
            "side";
        grid-template-rows: auto;
    }

    .room-side {
        max-height: none;
        overflow: visible;
        contain: none;
    }
}
