:root {
    /* ライトモード用変数 */
    --bg: #f0f2f5;
    --card: #ffffff;
    --display: #f8f9fa;
    --text: #1a1a1b;
    --text-dim: #70757a;
    --accent: #1a73e8;
    --btn-num: #ffffff;
    --btn-op: #f1f3f4;
    --btn-sci: #e8f0fe;
}

.dark-mode {
    --bg: #121212;
    --card: #1e1e1e;
    --display: #2d2d2d;
    --text: #e8eaed;
    --text-dim: #9aa0a6;
    --accent: #8ab4f8;
    --btn-num: #3c4043;
    --btn-op: #5f6368;
    --btn-sci: #3c4043;
}

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    height: 100dvh; /* 動的ビューポート高さ */
    display: flex;
    justify-content: center;
    overflow: hidden; /* スクロール禁止 */
}

.app-container {
    width: 100%;
    max-width: 450px;
    height: 100%;
    padding: 10px;
    display: grid;
    grid-template-rows: auto 1fr auto; /* ヘッダー、電卓、フッター */
    gap: 10px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
}

h1 { font-size: 1.2rem; margin: 0; font-weight: 500; }

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
}

/* 電卓本体 */
.calculator {
    display: grid;
    grid-template-rows: 140px 1fr; /* ディスプレイ固定、キーパッド可変 */
    gap: 15px;
    height: 100%;
}

.display {
    background: var(--display);
    border-radius: 16px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: right;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.display-top {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--text-dim);
}

.nav-btn {
    background: none;
    border: none;
    color: var(--accent);
    padding: 0 5px;
    cursor: pointer;
}

#inputLabel {
    font-size: clamp(1.5rem, 8vw, 2.5rem);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
}

#footerLabel {
    font-size: 0.9rem;
    color: var(--accent);
    height: 1.2rem;
}

/* キーパッド */
.keypad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    height: 100%;
}

.btn {
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    transition: filter 0.1s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn:active {
    transform: scale(0.95);
    filter: brightness(0.8);
}

.btn.num { background: var(--btn-num); color: var(--text); }
.btn.op { background: var(--btn-op); color: var(--text); }
.btn.sci { background: var(--btn-sci); color: var(--accent); font-size: 0.9rem; }
.btn.func { background: var(--btn-op); color: #f28b82; }
.btn.equal { grid-column: span 3; background: var(--accent); color: white; }

.copy-section {
    padding: 5px;
    text-align: center;
}

.copyright { font-size: 0.8rem; color: var(--text-dim); margin: 0; cursor: pointer; }
