* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #fff;
    color: #1a1a1a;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* ---- 언어 선택 화면 ---- */
#lang-select-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
}

#lang-select-screen h1 {
    font-size: 28px;
    margin-bottom: 32px;
}

.lang-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
    width: 100%;
    max-width: 560px;
}

.lang-grid.small {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
    margin-bottom: 16px;
}

.lang-grid button {
    padding: 24px 12px;
    font-size: 20px;
    font-weight: 600;
    border: 2px solid #222;
    border-radius: 12px;
    background: #fff;
    color: #222;
    cursor: pointer;
}

.lang-grid.small button {
    padding: 10px 8px;
    font-size: 15px;
}

.lang-grid button:hover,
.lang-grid button:focus {
    background: #222;
    color: #fff;
}

.footer-link {
    margin-top: 40px;
    color: #888;
    font-size: 13px;
    text-decoration: none;
}

.footer-link:hover {
    color: #444;
}

/* ---- 글자판 화면 ---- */
#board-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
}

.top-bar {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    border-bottom: 1px solid #e5e5e5;
    flex-shrink: 0;
}

.menu-btn {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    font-size: 22px;
    background: none;
    border: none;
    cursor: pointer;
    color: #222;
}

.app-title {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
}

.input-row {
    display: flex;
    gap: 10px;
    padding: 16px 16px 0 16px;
    flex-shrink: 0;
}

.output {
    flex: 1;
    min-height: 56px;
    max-height: 90px;
    padding: 14px 16px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 22px;
    line-height: 1.3;
    word-break: break-all;
    overflow-y: auto;
    cursor: pointer;
}

.output:empty::before {
    content: '글자를 입력해주세요.';
    color: #aaa;
}

.scroll-buttons {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.scroll-buttons button {
    width: 36px;
    flex: 1;
    background: #eee;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    color: #555;
}

.quick-phrases {
    display: flex;
    gap: 8px;
    padding: 12px 16px 0 16px;
    overflow-x: auto;
    flex-shrink: 0;
}

.chip {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    background: #e9edfb;
    color: #3548c9;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 14px;
}

.chip-text {
    cursor: pointer;
    white-space: nowrap;
}

.chip-remove {
    border: none;
    background: none;
    color: #7783d6;
    cursor: pointer;
    font-size: 12px;
    padding: 0;
}

/* ---- 클러스터 휠(원형 그룹) ---- */
.wheel {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: repeat(4, 150px);
    align-content: start;
    align-items: center;
    justify-items: center;
    gap: 8px;
    padding: 16px;
}

.action-btn,
.cluster {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    align-content: center;
    width: 100%;
    max-width: 150px;
    aspect-ratio: 1 / 1;
    border-radius: 50%;
    background: #ececec;
    border: none;
    cursor: pointer;
    font-size: 17px;
    font-weight: 600;
    color: #1a1a1a;
    row-gap: 4px;
}

.action-btn {
    grid-column: 2;
    grid-row: 1;
    font-size: 18px;
    background: #ececec;
}

.cluster-ml { grid-column: 1; grid-row: 2; }
.cluster-mr { grid-column: 3; grid-row: 2; }
.cluster-bl { grid-column: 1; grid-row: 3; }
.cluster-br { grid-column: 3; grid-row: 3; }
.cluster-bc { grid-column: 2; grid-row: 4; }

.cluster span {
    flex: 0 0 42%;
    text-align: center;
    padding: 2px;
}

.cluster span.solo-item {
    flex: 0 0 100%;
    font-size: 30px;
}

.cluster.empty {
    visibility: hidden;
}

.action-btn.scan-highlight,
.cluster.scan-highlight {
    background: #3d5bfd;
    color: #fff;
}

.cluster.scan-highlight span.scan-highlight {
    background: #ffd400;
    color: #000;
    border-radius: 6px;
}

/* ---- 하단 바 ---- */
.bottom-bar {
    display: flex;
    flex-shrink: 0;
}

.bottom-bar button {
    flex: 1;
    padding: 18px;
    font-size: 17px;
    font-weight: 600;
    border: none;
    background: #d9d9d9;
    color: #333;
    cursor: pointer;
}

.bottom-bar button.danger {
    background: #3d5bfd;
    color: #fff;
}

/* ---- 메뉴 모달 ---- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 10;
}

.modal-content {
    background: #fff;
    border-radius: 14px;
    padding: 24px;
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content h2 {
    margin-top: 0;
}

.modal-content > div {
    margin-bottom: 20px;
}

.modal-content label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
}

.mode-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: normal;
    margin-bottom: 8px;
}

.mode-option input {
    width: auto;
}

#scan-speed {
    width: 100%;
}

.modal-content .secondary-btn {
    width: 100%;
    padding: 10px;
    background: #eee;
    color: #222;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 4px;
}

.modal-content #close-menu {
    width: 100%;
    padding: 12px;
    background: #222;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    margin-top: 12px;
}
