body {
    margin: 0;
    font-family: sans-serif;
    display: flex;
    justify-content: center;
    height: 100vh;
    transition: .3s;
    touch-action: manipulation;
}

/* APP */
.app {
    width: 100%;
    padding: 20px;
    padding-top: calc(env(safe-area-inset-top, 0px) + 20px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* TOPBAR */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding: 8px 14px;
    border-radius: 8px;
    background: linear-gradient(180deg, #e8e8e8 0%, #f5f5f5 15%, #d0d0d0 30%, #e0e0e0 50%, #c8c8c8 70%, #dcdcdc 85%, #b8b8b8 100%);
    border-top: 1px solid #f0f0f0;
    border-bottom: 1px solid #999;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
    transition: background 0.3s, border-color 0.3s;
}

/* THEME DOT */
.theme-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 6px rgba(0, 0, 0, .3);
    transition: .25s;
    background: #333;
}

.theme-dot:hover {
    transform: scale(1.2);
}

/* TOOLS BAR (ปุ่มด้านบน) */
.tools {
    display: flex;
    gap: 8px;
    align-items: center;
}

.tools button {
    height: 36px;
    width: 36px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    color: #333;
    border: none;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: 0.2s;
}

.tools button:hover {
    background: rgba(255, 255, 255, 0.9);
    transform: scale(1.05);
}

.tools button.active {
    background: #4caf50;
    color: white;
}

/* DISPLAY */
.display-wrap {
    background: linear-gradient(180deg, #c8c8c8, #e2e2e2);
    border-radius: 4px;
    border-top: 3px solid #888;
    border-left: 3px solid #999;
    border-right: 3px solid #f0f0f0;
    border-bottom: 3px solid #fff;
    margin-bottom: 10px;
    transition: background 0.3s, border-color 0.3s;
}

.display {
    padding: clamp(10px, 1.5vh, 24px) clamp(14px, 2vh, 32px);
    font-size: clamp(32px, 5vh, 56px);
    font-weight: 700;
    text-align: right;
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    color: #333;
    transition: color 0.3s;
}

/* BUTTON GRID */
.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: clamp(6px, 1vh, 12px);
    margin-bottom: clamp(4px, 0.8vh, 10px);
}

button {
    height: clamp(52px, 7.5vh, 100px);
    border: none;
    border-radius: clamp(8px, 1.5vh, 16px);
    font-size: clamp(18px, 3vh, 32px);
    cursor: pointer;
    background: white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, .2);
    transition: all 0.2s ease;
    color: #333;
}

button:hover {
    transform: scale(1.05);
}

/* ปุ่มตัวเลข */
.btn-number {
    background: linear-gradient(180deg, #e8f4f8 0%, #d0e8f0 50%, #b8dce8 100%);
    color: #1a5276;
    font-weight: 700;
    border-top: 1px solid #f0f8ff;
    border-bottom: 1px solid #7fb3d5;
}

.btn-number:hover {
    background: linear-gradient(180deg, #d0e8f0 0%, #b8dce8 50%, #a0d0e0 100%);
    box-shadow: 0 4px 8px rgba(26, 82, 118, 0.3);
}

/* ปุ่ม C */
.btn-clear {
    background: linear-gradient(180deg, #ffe8e8 0%, #ffc8c8 50%, #ffa8a8 100%);
    color: #922b21;
    font-weight: 800;
    border-top: 1px solid #fff0f0;
    border-bottom: 1px solid #c0392b;
}

.btn-clear:hover {
    background: linear-gradient(180deg, #ffc8c8 0%, #ffa8a8 50%, #ff8888 100%);
    box-shadow: 0 4px 8px rgba(146, 43, 33, 0.3);
}

.zero {
    grid-column: span 2;
}

.hidden {
    display: none;
}

/* HISTORY */
.history {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 10px;
    margin-top: 4px;
    border-radius: 10px;
    font-size: clamp(13px, 2vh, 22px);
    opacity: 0.5;
    transition: color 0.3s;
}

.history div {
    padding: 4px 0;
    text-align: right;
}

/* ABOUT MODAL */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(2px);
}

.modal-overlay.hidden {
    display: none;
}

.modal-box {
    background: white;
    padding: 24px;
    border-radius: 16px;
    text-align: center;
    min-width: 250px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    color: #333;
}

.modal-box h3 {
    margin: 0 0 8px 0;
    font-size: 24px;
    color: #222;
}

.modal-box p {
    margin: 0 0 20px 0;
    color: #666;
}

.modal-close-btn {
    background: #4caf50;
    color: white;
    padding: 8px 24px;
    border-radius: 20px;
    font-size: 16px;
    height: auto;
    width: auto;
    box-shadow: none;
    cursor: pointer;
    border: none;
}


/* =========================================
   THEMES (แก้ไขบั๊กและเพิ่มสีให้ครบ)
   ========================================= */

/* LIGHT (Default) ใช้ค่าดั้งเดิม */

/* SILVER */
body.silver {
    background: linear-gradient(135deg, #e8e8e8 0%, #f5f5f5 50%, #d0d0d0 100%);
}

body.silver .theme-dot {
    background: linear-gradient(135deg, #c0c0c0, #e8e8e8, #a0a0a0);
    border: 1px solid #888;
}

body.silver .display {
    color: #4a4a4a;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5);
}

body.silver .display-wrap {
    background: linear-gradient(180deg, #b8b8b8, #e0e0e0);
    border-top: 3px solid #909090;
    border-left: 3px solid #a0a0a0;
    border-right: 3px solid #f8f8f8;
    border-bottom: 3px solid #fff;
}

body.silver .topbar {
    background: linear-gradient(180deg, #d8d8d8 0%, #f0f0f0 15%, #c0c0c0 30%, #e0e0e0 50%, #b0b0b0 70%, #d0d0d0 85%, #a8a8a8 100%);
    border-top: 1px solid #f5f5f5;
    border-bottom: 1px solid #808080;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

body.silver .btn-number {
    background: linear-gradient(180deg, #f5f5f5 0%, #e0e0e0 50%, #c8c8c8 100%);
    color: #505050;
    border-top: 1px solid #fff;
    border-bottom: 1px solid #888;
}

body.silver .btn-number:hover {
    background: linear-gradient(180deg, #e0e0e0 0%, #c8c8c8 50%, #b0b0b0 100%);
}

body.silver .btn-clear {
    background: linear-gradient(180deg, #e8d8d8 0%, #d0c0c0 50%, #b8a8a8 100%);
    color: #6b4040;
    border-top: 1px solid #f0e0e0;
    border-bottom: 1px solid #806060;
}

body.silver .history {
    color: #666;
}

/* GOLD */
body.gold {
    background: linear-gradient(135deg, #f5e6c8 0%, #faf0d8 50%, #e8d4a8 100%);
}

body.gold .theme-dot {
    background: linear-gradient(135deg, #d4af37, #f4d03f, #b8860b);
    border: 1px solid #a08020;
}

body.gold .display {
    color: #5a4a20;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.3);
}

body.gold .display-wrap {
    background: linear-gradient(180deg, #d4c4a8, #f0e8d0);
    border-top: 3px solid #a08040;
    border-left: 3px solid #b09050;
    border-right: 3px solid #fff8e8;
    border-bottom: 3px solid #fff;
}

body.gold .topbar {
    background: linear-gradient(180deg, #e8d8b8 0%, #f5ecd0 15%, #d4c090 30%, #e8dcb0 50%, #c8b080 70%, #dcc8a0 85%, #b8a070 100%);
    border-top: 1px solid #f5ecd8;
    border-bottom: 1px solid #8b7355;
    box-shadow: 0 2px 4px rgba(139, 115, 85, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

body.gold .btn-number {
    background: linear-gradient(180deg, #faf5e0 0%, #f0e8c8 50%, #e8dcb0 100%);
    color: #6b5a30;
    border-top: 1px solid #fffef5;
    border-bottom: 1px solid #a08040;
}

body.gold .btn-number:hover {
    background: linear-gradient(180deg, #f0e8c8 0%, #e8dcb0 50%, #d4c490 100%);
}

body.gold .btn-clear {
    background: linear-gradient(180deg, #f5e0d8 0%, #e8c8b8 50%, #dcb0a0 100%);
    color: #8b4513;
    border-top: 1px solid #fff0e8;
    border-bottom: 1px solid #a06040;
}

body.gold .history {
    color: #7a6a40;
}

/* CANDY */
body.candy {
    background: linear-gradient(135deg, #ffb6c1, #ffc0cb, #f08080);
}

body.candy .theme-dot {
    background: #ff69b4;
    border: 2px solid #fff;
}

body.candy .topbar {
    background: linear-gradient(180deg, #ffe4e1, #ffb6c1);
    border-color: #ffb6c1;
}

body.candy .display-wrap {
    background: #fff0f5;
    border-color: #ff69b4 #ff1493 #fff #ff69b4;
}

body.candy .display {
    color: #d81b60;
}

body.candy button {
    color: #d81b60;
}

body.candy .btn-number {
    background: linear-gradient(180deg, #fff0f5 0%, #ffe4e1 50%, #ffb6c1 100%);
    color: #d81b60;
    border-top: 1px solid #fff;
    border-bottom: 1px solid #ff69b4;
}

body.candy .btn-number:hover {
    background: linear-gradient(180deg, #ffe4e1 0%, #ffb6c1 50%, #ff9eaf 100%);
}

body.candy .btn-clear {
    background: #ff1493;
    color: #fff;
    border-bottom: 1px solid #c71585;
}

body.candy .history {
    color: #fff;
    opacity: 0.8;
}

/* MINT */
body.mint {
    background: linear-gradient(135deg, #98ff98, #f5fffa, #3cb371);
}

body.mint .theme-dot {
    background: #2e8b57;
    border: 2px solid #fff;
}

body.mint .topbar {
    background: linear-gradient(180deg, #e0ffff, #98ff98);
    border-color: #98ff98;
}

body.mint .display-wrap {
    background: #f0fff0;
    border-color: #3cb371 #2e8b57 #fff #3cb371;
}

body.mint .display {
    color: #006400;
}

body.mint button {
    color: #006400;
}

body.mint .btn-number {
    background: linear-gradient(180deg, #f5fffa 0%, #e0ffe0 50%, #b3ffb3 100%);
    color: #006400;
    border-top: 1px solid #fff;
    border-bottom: 1px solid #3cb371;
}

body.mint .btn-number:hover {
    background: linear-gradient(180deg, #e0ffe0 0%, #b3ffb3 50%, #98ff98 100%);
}

body.mint .btn-clear {
    background: #3cb371;
    color: #fff;
    border-bottom: 1px solid #2e8b57;
}

body.mint .history {
    color: #004d00;
}

/* SUNSET */
body.sunset {
    background: linear-gradient(135deg, #ff7e5f, #feb47b);
}

body.sunset .theme-dot {
    background: #ff4500;
    border: 2px solid #fff;
}

body.sunset .topbar {
    background: linear-gradient(180deg, #ffdcb5, #ffa07a);
    border-color: #ff7e5f;
}

body.sunset .display-wrap {
    background: #fff5ee;
    border-color: #ff6347 #ff4500 #fff #ff6347;
}

body.sunset .display {
    color: #8b0000;
}

body.sunset button {
    color: #8b0000;
}

body.sunset .btn-number {
    background: linear-gradient(180deg, #fff0e6 0%, #ffe4d6 50%, #ffcba4 100%);
    color: #b22222;
    border-top: 1px solid #fff;
    border-bottom: 1px solid #ff7e5f;
}

body.sunset .btn-number:hover {
    background: linear-gradient(180deg, #ffe4d6 0%, #ffcba4 50%, #ffa07a 100%);
}

body.sunset .btn-clear {
    background: #ff4500;
    color: #fff;
    border-bottom: 1px solid #cd3300;
}

body.sunset .history {
    color: #fff;
}

/* OCEAN */
body.ocean {
    background: linear-gradient(135deg, #2b5876, #4e4376);
}

body.ocean .theme-dot {
    background: #00bfff;
    border: 2px solid #fff;
}

body.ocean .topbar {
    background: linear-gradient(180deg, #4ca1af, #c4e0e5);
    border-color: #2b5876;
}

body.ocean .display-wrap {
    background: #e0f7fa;
    border-color: #008080 #006666 #fff #008080;
}

body.ocean .display {
    color: #004d4d;
}

body.ocean button {
    color: #004d4d;
}

body.ocean .btn-number {
    background: linear-gradient(180deg, #e0f7fa 0%, #b2ebf2 50%, #80deea 100%);
    color: #006060;
    border-top: 1px solid #fff;
    border-bottom: 1px solid #00acc1;
}

body.ocean .btn-number:hover {
    background: linear-gradient(180deg, #b2ebf2 0%, #80deea 50%, #4dd0e1 100%);
}

body.ocean .btn-clear {
    background: #008080;
    color: #fff;
    border-bottom: 1px solid #006666;
}

body.ocean .history {
    color: #e0f7fa;
}

/* MIDNIGHT (Premium Dark Mode) */
body.midnight {
    background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
}

body.midnight .theme-dot {
    background: linear-gradient(135deg, #a770ef, #cf8bf3, #fdb99b);
    box-shadow: 0 0 10px rgba(167, 112, 239, 0.6);
    border: 1px solid #fff;
}

body.midnight .topbar {
    background: linear-gradient(180deg, rgba(32, 58, 67, 0.8), rgba(15, 32, 39, 0.9));
    border: 1px solid rgba(167, 112, 239, 0.4);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6), 0 0 15px rgba(167, 112, 239, 0.2);
    backdrop-filter: blur(8px);
}

body.midnight .display-wrap {
    background: linear-gradient(180deg, #081216, #122128);
    border: 2px solid rgba(0, 229, 255, 0.4);
    box-shadow: 0 0 15px rgba(0, 229, 255, 0.15), inset 0 2px 10px rgba(0, 0, 0, 0.8);
}

body.midnight .display {
    color: #00e5ff;
    text-shadow: 0 0 12px rgba(0, 229, 255, 0.5);
    font-weight: 800;
}

body.midnight button {
    background: linear-gradient(180deg, #2a3e4b, #1f303a);
    color: #a1c4cf;
    border: 1px solid rgba(161, 196, 207, 0.1);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
}

body.midnight button:hover {
    background: linear-gradient(180deg, #324a59, #243844);
    color: #fff;
    transform: scale(1.05);
    border-color: rgba(0, 229, 255, 0.4);
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.2);
}

body.midnight .btn-number {
    background: linear-gradient(180deg, #1c2b33, #131e24);
    color: #f0f8ff;
    border: 1px solid rgba(0, 229, 255, 0.15);
}

body.midnight .btn-number:hover {
    background: linear-gradient(180deg, #243842, #18272e);
    border-color: rgba(0, 229, 255, 0.6);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.3);
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
}

body.midnight .btn-clear {
    background: linear-gradient(180deg, #5c162b, #400a18);
    color: #ff6b81;
    border: 1px solid rgba(255, 107, 129, 0.3);
}

body.midnight .btn-clear:hover {
    background: linear-gradient(180deg, #751d38, #520f21);
    color: #fff;
    border-color: rgba(255, 107, 129, 0.8);
    box-shadow: 0 0 15px rgba(255, 107, 129, 0.5);
    text-shadow: 0 0 8px rgba(255, 107, 129, 0.8);
}

body.midnight .tools button {
    background: rgba(255, 255, 255, 0.05);
    color: #00e5ff;
    border: 1px solid rgba(0, 229, 255, 0.2);
}

body.midnight .tools button:hover {
    background: rgba(0, 229, 255, 0.15);
    color: #fff;
    border-color: rgba(0, 229, 255, 0.6);
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.4);
}

body.midnight .tools button.active {
    background: #00e5ff;
    color: #000;
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.6);
    border-color: transparent;
}

body.midnight .history {
    color: #587d8f;
}