@charset "UTF-8";

:root {
	--accent-color: #0f0;
	/* ボタンやディスプレイのアクセント（ダーク用） */
	--history-text-color: var(--accent-color);
	/* 履歴表示色（実際に使う色） */
}

/* 履歴で使う色を参照する */
.history-panel,
.history-panel .history-item,
.history-panel .history-item .res {
	color: var(--history-text-color);
}

/* ライトモードでは履歴の色を上書きする場合に備えたクラス */
body.light-mode {
	--bg-color: #f0f0f0;
}

:root {
	--bg-color: #222;
	--btn-color: #444;
	--btn-hover: #666;
	--text-color: #0f0;
}

* {
	box-sizing: border-box
}

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

body {
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP", "Yu Gothic", sans-serif;
	background: var(--bg-color);
	color: var(--text-color);
	display: flex;
	justify-content: center;
	align-items: center;
	min-height: 100vh;
	padding: 16px;
}

/* ラッパー */
.container {
	width: 100%;
	max-width: 1100px;
	display: flex;
	gap: 20px;
	align-items: stretch;
	justify-content: center;
}

/* 電卓 */
.calculator {
	flex: 1 1 65%;
	max-width: 720px;
	background: #1a1a1a;
	border: 2px solid #555;
	border-radius: 12px;
	padding: 16px;
	box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
	display: flex;
	flex-direction: column;
	min-height: 420px;
}

.controls {
	margin-bottom: 8px;
	text-align: center
}

select {
	font-size: 0.95em;
	padding: 6px;
	margin: 0 6px
}

.display {
	background: #000;
	color: var(--text-color);
	font-size: 2.2rem;
	text-align: right;
	padding: 12px;
	border-radius: 8px;
	overflow-x: auto;
	white-space: nowrap;
	margin-bottom: 10px;
	flex: 0 0 auto;
}

/* ボタン群 */
.buttons {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 8px;
	flex: 1 1 auto;
	overflow: auto;
	padding-bottom: 6px;
}

button {
	font-size: 1.05rem;
	padding: 12px;
	border-radius: 8px;
	border: none;
	cursor: pointer;
	transition: background .12s, transform .06s;
	min-height: 48px;
}

.digit,
.operator {
	background: #444;
	color: #fff
}

.control {
	background: var(--btn-color);
	color: #fff
}

button:hover {
	background: var(--btn-hover)
}

button:active {
	transform: scale(.98);
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, .3)
}

/* 履歴パネル：初期高さを固定（親の高さに依らず指定） */
.history-panel {
	flex: 0 0 30%;
	max-width: 340px;
	width: 300px;
	background: #111;
	border-radius: 10px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
	/* 初期固定高さ（ここで固定） */
	height: 520px;
	/* 最小・最大で幅は維持、内部のみスクロール */
	min-height: 420px;
	max-height: 80vh;
	display: flex;
	flex-direction: column;
	overflow: visible;
}

.history-header {
	padding: 12px;
	border-bottom: 1px solid #1b1b1b;
	flex: 0 0 auto;
	background: linear-gradient(180deg, rgba(255, 255, 255, 0.01), transparent);
}

.history-header h3 {
	margin: 0;
	font-size: 1.05rem;
	opacity: .95
}

/* 内部スクロール領域（高さは親の height を使う） */
.history-list {
	padding: 8px 12px;
	overflow-y: auto;
	flex: 1 1 auto;
}

.history-item {
	padding: 8px 6px;
	border-bottom: 1px solid #222;
	margin-bottom: 8px;
	cursor: pointer
}

.history-item .expr {
	opacity: .95
}

.history-item .res {
	opacity: .8;
	margin-top: 4px;
	font-weight: 600
}

.history-item:hover {
	background: rgba(255, 255, 255, 0.02)
}

/* デスクトップ補助: 縦に増え過ぎないように親の最大高さを設定 */
@media (min-width:721px) {
	.container {
		max-height: 90vh;
	}

	.calculator {
		min-height: 520px;
	}
}

/* モバイル: 縦積み、履歴は短めでスクロール */
@media (max-width:720px) {
	body {
		align-items: center;
		padding: 10px
	}

	.container {
		flex-direction: column;
		align-items: center;
		gap: 12px;
		max-width: 640px
	}

	.calculator {
		order: 1;
		width: 100%;
		max-width: 640px;
		padding: 12px;
		min-height: unset
	}

	.display {
		font-size: 1.6rem;
		padding: 10px
	}

	.buttons {
		gap: 6px
	}

	button {
		font-size: .98rem;
		padding: 10px;
		min-height: 44px
	}

	.history-panel {
		order: 3;
		width: 100%;
		max-width: 640px;
		/* モバイルでは高さを小さめに固定 */
		height: 220px;
		max-height: 36vh;
	}

	.history-list {
		max-height: inherit
	}
}

/* スクロールバー見た目 */
.history-list::-webkit-scrollbar {
	width: 10px
}

.history-list::-webkit-scrollbar-thumb {
	background: #333;
	border-radius: 6px
}

@media (max-width: 720px) {
  /* 全体をビューポート高さで固定し、外側のスクロールを抑える */
  html, body {
    height: 100vh;
    margin: 0;
    padding: 0;
    overflow: hidden; /* 外側のスクロールを止める（内部でスクロールさせる） */
  }

  /* 縦並びにして container 自体を 100vh に収める */
  .container {
    display: flex;
    flex-direction: column;
    height: 100vh; /* 画面全体を占有 */
    gap: 12px;
    align-items: center;
    max-width: 640px;
    width: 100%;
    overflow: hidden; /* 外側スクロール無し */
  }

  /* メイン電卓領域：高さは残り領域を占める、内部をスクロール可能に */
  .calculator {
    order: 1;
    width: 100%;
    padding: 12px;
    min-height: 0;          /* ← ここが重要: flex 子が縮むために必須 */
    flex: 1 1 auto;         /* 残り領域を占有 */
    overflow: auto;         /* 内部スクロール有効（ボタン群など） */
  }

  .display { font-size: 1.6rem; padding: 10px; }

  .buttons { gap: 6px; }

  button { font-size: .98rem; padding: 10px; min-height: 44px; }

  /* 履歴パネルは固定高さ（vhベース）にして内部だけスクロール */
  .history-panel {
    order: 3;
    width: 100%;
    max-width: 640px;
    height: 28vh;          /* 画面高さの割合で固定（必要に応じて調整） */
    max-height: 36vh;
    min-height: 120px;
    flex: 0 0 auto;        /* 縮まない */
    overflow: hidden;      /* 外側にはみ出さない */
    display: flex;
    flex-direction: column;
  }

  /* 履歴リストだけスクロール */
  .history-list {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* iOSでスムーズスクロール */
  }
}
