* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
}

body {
    background: #18171c;
    color: #e3e5eb;
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Helvetica Neue",
        Arial,
        sans-serif;
    font-size: 14px;
    overflow: hidden;
    position: fixed;
    inset: 0;
}

button,
input {
    font-family: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.head {
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 5px 8px;
    background: #242329;
    border-bottom: 1px solid #3a3940;
}

.viewerMenuButton {
    width: 38px;
    height: 32px;
    border: 0;
    border-radius: 7px;
    background: #3a393f;
    color: #e3e5eb;
    font-size: 21px;
    line-height: 32px;
    cursor: pointer;
}

main {
    width: 100%;
    height: calc(100% - 42px);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.inputFields {
    padding: 8px;
    background: #202025;
    border-bottom: 1px solid #35343a;
    flex-shrink: 0;
}

.inputRow {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 6px;
}

#uniqueIdInput {
    flex: 1;
    min-width: 0;
    height: 38px;
    padding: 0 11px;
    border: 1px solid #4a494f;
    border-radius: 7px;
    outline: none;
    background: #303035;
    color: #f1f1f3;
    font-size: 14px;
}

#uniqueIdInput::placeholder {
    color: #9b9ba2;
}

#uniqueIdInput:focus {
    border-color: #697080;
}

#copyUrlButton {
    flex-shrink: 0;
    height: 38px;
    padding: 0 11px;
    border: 0;
    border-radius: 7px;
    background: #3e414a;
    color: #f0f1f4;
    font-size: 13px;
    cursor: pointer;
}

#connectButton {
    width: 100%;
    height: 38px;
    margin-top: 6px;
    border: 0;
    border-radius: 7px;
    background: #4b5362;
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

#connectButton:active,
#copyUrlButton:active,
.viewerMenuButton:active {
    opacity: 0.75;
}

.statusBar {
    min-height: 36px;
    padding: 5px 9px;
    background: #1f1e23;
    border-bottom: 1px solid #35343a;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
    overflow: hidden;
}

#stateText {
    margin: 0;
    padding: 0;
    color: #bfc2ca;
    font-size: 12px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

#roomStats {
    flex-shrink: 0;
    color: #c9cbd1;
    font-size: 12px;
    text-align: right;
    white-space: nowrap;
}


/* ========================================
   メイン領域
   ======================================== */

.mainContent {
    flex: 1;
    min-height: 0;

    display: grid;

    grid-template-columns:
        minmax(0, 1.5fr)
        minmax(210px, 0.5fr);

    gap: 3px;

    padding: 0 6px 2px 6px;

    overflow: hidden;
    overscroll-behavior: none;
}


/* ========================================
   ギフト拡大
   ======================================== */

.mainContent.giftExpanded {
    grid-template-columns: minmax(0, 1fr);
}

.mainContent.giftExpanded .chatcontainer {
    display: none;
}

.mainContent.giftExpanded .giftcontainer {
    width: 100%;
}


/* ========================================
   チャット・ギフト本体
   ======================================== */

.chatcontainer,
.giftcontainer {
    min-width: 0;
    min-height: 0;

    overflow-y: auto;
    overflow-x: hidden;

    background: #202025;
    border: 1px solid #36353b;
    border-radius: 8px;

    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;

    scrollbar-width: thin;
}

.chatcontainer {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.giftcontainer {
    display: flex;
    flex-direction: column;

    overflow-y: auto;
    overflow-x: hidden;

    min-height: 0;
    max-height: 100%;
    height: 100%;

    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}


/* ========================================
   見出し
   ======================================== */

.containerheader {
    position: sticky;
    top: 0;
    z-index: 2;

    flex-shrink: 0;

    margin: 0;
    padding: 7px 9px;

    background: #2a292f;
    border-bottom: 1px solid #3a3940;

    color: #dfe1e7;
    font-size: 13px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 8px;
}

.giftHeaderButtons {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.containerActionButton {
    flex-shrink: 0;

    width: 30px;
    height: 25px;

    padding: 0;

    border: 0;
    border-radius: 6px;

    background: #3a393f;
    color: #e5e6ea;

    font-size: 14px;
    line-height: 25px;
    text-align: center;

    cursor: pointer;
}

.containerActionButton:active {
    opacity: 0.7;
}

#chatAutoScrollButton {
    font-size: 15px;
}

#chatAutoScrollButton.autoScrollOff {
    background: #4b5362;
    color: #ffffff;
}

#giftAudioButton.audioOff {
    background: #4b5362;
    color: #ffffff;
}

#giftExpandButton.expanded {
    background: #4b5362;
    color: #ffffff;
}


/* ========================================
   チャット
   ======================================== */

.chatcontainer > div,
.giftcontainer > div {
    min-width: 0;
}

.chatcontainer > div {
    display: flex;
    align-items: flex-start;

    gap: 7px;

    padding: 5px 7px;

    border-bottom: 1px solid rgba(255, 255, 255, 0.035);

    line-height: 1.4;

    flex-shrink: 0;
}


/* ========================================
   ギフト
   ======================================== */

.giftcontainer > div {
    min-width: 0;

    width: calc(100% - 8px);

    margin: 4px 4px 5px 4px;
    padding: 4px 5px;

    background: #29282e;
    border-radius: 6px;
    border: 1px solid #39383e;

    overflow: hidden;

    line-height: 1.2;

    flex-shrink: 0;
}

.miniprofilepicture {
    width: 30px;
    height: 30px;

    flex: 0 0 30px;

    border-radius: 50%;
    object-fit: cover;

    background: #3a393f;
}

.giftcontainer .miniprofilepicture {
    width: 22px;
    height: 22px;
    flex-basis: 22px;
}

.usernamelink {
    color: #8ea8df;
    text-decoration: none;
}

.giftcontainer > div > span,
.giftcontainer > div span {
    min-width: 0;
}


/* ========================================
   ギフトテーブル
   ======================================== */

.giftcontainer table {
    width: 100%;
    max-width: 100%;

    table-layout: fixed;
    border-collapse: collapse;

    margin-top: 3px;
}

.giftcontainer td {
    padding: 0;
    vertical-align: middle;
}

.giftcontainer td:first-child {
    width: 40px;
    padding-right: 5px;
}

.giftcontainer td:last-child {
    min-width: 0;
    width: auto;

    overflow: hidden;
}

.gifticon {
    display: block;

    width: 30px;
    height: 30px;

    max-width: 30px;
    max-height: 30px;

    object-fit: contain;
}

.giftcontainer table span {
    display: inline-block;

    max-width: 100%;

    overflow-wrap: anywhere;
    word-break: break-word;
}

.giftcontainer .giftTitle {
    font-size: 10px;
    line-height: 1.2;
}

.giftcontainer .giftDetail {
    font-size: 9px;
    line-height: 1.2;

    color: #c7c8ce;
}

.giftcontainer .giftDetail b {
    color: #e5e6ea;
}


/* ========================================
   イベント
   ======================================== */

.eventcontainer {
    width: 100%;
    min-height: 100%;
    overflow: hidden;
}

.eventcontainer > div {
    max-width: 100%;
    overflow-wrap: anywhere;
}

.splitstatetable {
    width: 100%;
    border-collapse: collapse;
}

.splitstatetable td {
    padding: 4px;
    vertical-align: middle;
}


/* ========================================
   視聴者サイドメニュー
   ======================================== */

.viewerSideMenu {
    position: fixed;
    z-index: 1000;

    top: 0;
    right: 0;

    width: min(320px, 82vw);
    height: 100%;

    background: #222127;

    border-left: 1px solid #3b3a41;

    box-shadow:
        -8px 0 24px rgba(0, 0, 0, 0.35);

    transform: translateX(100%);
    transition: transform 0.2s ease;

    display: flex;
    flex-direction: column;

    overflow: hidden;
}

.viewerSideMenu.open {
    transform: translateX(0);
}

.viewerMenuHeader {
    height: 46px;

    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 0 10px;

    background: #2a292f;

    border-bottom: 1px solid #3b3a41;

    font-weight: 600;
}

#viewerMenuClose {
    width: 32px;
    height: 32px;

    border: 0;
    border-radius: 6px;

    background: #3a393f;
    color: #e5e6ea;

    font-size: 21px;
}

.viewerCountText {
    padding: 8px 10px;

    color: #bfc1c8;
    font-size: 12px;

    border-bottom: 1px solid #35343a;

    flex-shrink: 0;
}

.viewerList {
    flex: 1;
    min-height: 0;

    overflow-y: auto;

    padding: 5px;

    overscroll-behavior: contain;
}

.viewerItem {
    display: flex;
    align-items: center;

    gap: 8px;

    padding: 6px;

    border-radius: 6px;
}

.viewerItem:hover {
    background: #2e2d33;
}

.viewerItem img {
    width: 30px;
    height: 30px;

    flex: 0 0 30px;

    border-radius: 50%;

    object-fit: cover;
}

.viewerItemText {
    min-width: 0;
    overflow: hidden;
}

.viewerItemNickname {
    color: #e3e4e8;

    font-size: 13px;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.viewerItemId {
    color: #92949c;

    font-size: 10px;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* ========================================
   視聴者メニュー背景
   ======================================== */

.viewerMenuOverlay {
    position: fixed;
    z-index: 999;

    inset: 0;

    background: rgba(0, 0, 0, 0.35);

    opacity: 0;

    pointer-events: none;

    transition: opacity 0.2s ease;
}

.viewerMenuOverlay.open {
    opacity: 1;
    pointer-events: auto;
}


/* ========================================
   スマホ
   ======================================== */

@media (max-width: 700px) {

    .mainContent {
        grid-template-columns: minmax(0, 1fr);

        /*
         * チャット : ギフト = 7 : 3
         * つまり 3.5 : 1.5
         */
        grid-template-rows: 6fr 4fr;

        padding: 0 6px 2px 6px;

        gap: 3px;
    }

    .mainContent.giftExpanded {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr);
    }

    .giftcontainer {
        min-height: 0;
    }

    .giftcontainer > div {
        width: calc(100% - 6px);

        margin-left: 3px;
        margin-right: 3px;
    }

    .gifticon {
        width: 32px;
        height: 32px;

        max-width: 32px;
        max-height: 32px;
    }

    .giftcontainer td:first-child {
        width: 37px;
    }

    #roomStats {
        font-size: 10px;
    }
}


/* ========================================
   小さいスマホ
   ======================================== */

@media (max-width: 420px) {

    .inputRow {
        gap: 5px;
    }

    #copyUrlButton {
        padding: 0 8px;
        font-size: 12px;
    }

    .mainContent {
        padding: 0 4px 2px 4px;

        /*
         * チャット : ギフト = 7 : 3
         */
        grid-template-rows: 7fr 3fr;

        gap: 2px;
    }

    .giftcontainer > div {
        padding: 4px 5px;
    }

    .giftcontainer .giftTitle {
        font-size: 10px;
    }

    .giftcontainer .giftDetail {
        font-size: 9px;
    }

    .gifticon {
        width: 30px;
        height: 30px;

        max-width: 30px;
        max-height: 30px;
    }

    .giftcontainer td:first-child {
        width: 35px;
        padding-right: 4px;
    }

    .containerActionButton {
        width: 29px;
        height: 24px;
        line-height: 24px;
    }
}
.giftcontainer {
    position: relative;
}

.giftcontainer .containerheader {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #2a292f !important;
    box-shadow: 0 0 0 2px #2a292f;
}