/* =============================================
   AIクエスト — レトロRPG風スタイル
   対象: 50代・PC初心者。文字は大きく、押せる物は明確に。
   ============================================= */

:root {
	--bg: #0d0d1f;
	--bg-deep: #07071a;
	--ink: #ffffff;
	--ink-soft: #cfd3ea;
	--gold: #f6b91a;
	--accent: #6ecf7f;
	--danger: #ff6b6b;
	--window-bg: rgba(10, 10, 34, 0.94);
	--font: 'DotGothic16', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', monospace, sans-serif;
}

* { box-sizing: border-box; }

/* hidden属性は どのdisplay指定よりも優先して非表示にする */
[hidden] { display: none !important; }

html, body {
	margin: 0;
	padding: 0;
	background: var(--bg-deep);
	color: var(--ink);
	font-family: var(--font);
	line-height: 1.8;
	-webkit-font-smoothing: none;
}

button {
	font-family: var(--font);
	cursor: pointer;
}

#game {
	position: relative;
	width: 100%;
	max-width: 960px;
	min-height: 100dvh;
	margin: 0 auto;
	background:
		radial-gradient(ellipse at 50% -10%, rgba(66, 66, 140, 0.35), transparent 55%),
		var(--bg);
	overflow: hidden;
}

/* ===== 共通: RPGウィンドウ ===== */
.rpg-window {
	position: relative;
	border: 3px solid #fff;
	border-radius: 10px;
	background: var(--window-bg);
	box-shadow:
		0 0 0 3px var(--bg-deep),
		0 0 0 5px rgba(255, 255, 255, 0.35),
		0 14px 40px rgba(0, 0, 0, 0.55);
	padding: 18px 20px;
}

/* ===== 共通: ボタン ===== */
.rpg-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 56px;
	border: 3px solid #fff;
	border-radius: 10px;
	background: #1b1b46;
	color: #fff;
	font-size: 1.05rem;
	padding: 10px 22px;
	transition: transform 0.12s ease, background 0.12s ease;
}

.rpg-btn:hover, .rpg-btn:focus-visible {
	background: #34347c;
	transform: translateY(-2px);
	outline: none;
}

.rpg-btn:active { transform: translateY(0); }

.rpg-btn:disabled {
	opacity: 0.4;
	cursor: not-allowed;
	transform: none;
}

.rpg-btn.small { min-height: 44px; font-size: 0.9rem; padding: 6px 14px; }

.rpg-btn.gold {
	background: #6b4d00;
	border-color: var(--gold);
	color: #ffe9ad;
}

.rpg-btn.gold:hover { background: #8a6400; }

/* ===== 画面共通 ===== */
.screen {
	min-height: 100dvh;
	display: flex;
	flex-direction: column;
}

/* ===== タイトル ===== */
#screen-title {
	align-items: center;
	justify-content: center;
	text-align: center;
	padding: 24px;
}

.title-eyebrow {
	margin: 0 0 18px;
	color: var(--gold);
	font-size: 0.95rem;
	letter-spacing: 0.1em;
}

.title-logo {
	margin: 0;
	font-size: clamp(3rem, 12vw, 5.2rem);
	line-height: 1.1;
	color: #fff;
	text-shadow:
		0 4px 0 #2a2a6a,
		0 8px 24px rgba(0, 0, 0, 0.6);
	letter-spacing: 0.06em;
}

.title-sub {
	margin: 10px 0 0;
	font-size: clamp(1rem, 3.4vw, 1.35rem);
	color: var(--ink-soft);
}

.title-hero {
	margin: 26px 0 8px;
	font-size: clamp(2.2rem, 8vw, 3.4rem);
	letter-spacing: 0.2em;
	animation: bob 2.4s ease-in-out infinite;
}

@keyframes bob {
	0%, 100% { transform: translateY(0); }
	50% { transform: translateY(-8px); }
}

.title-menu {
	display: flex;
	flex-direction: column;
	gap: 14px;
	width: min(340px, 86vw);
	margin: 22px auto 0;
}

.title-menu .rpg-btn { width: 100%; font-size: 1.2rem; }

.title-note {
	margin-top: 26px;
	color: var(--ink-soft);
	font-size: 0.92rem;
	line-height: 2;
}

/* ===== 名前入力 ===== */
#screen-name {
	align-items: center;
	justify-content: center;
	padding: 24px;
}

.name-window {
	width: min(520px, 92vw);
	text-align: center;
	padding: 30px 26px;
}

.name-lead { margin: 0 0 18px; font-size: 1.1rem; }

#name-input {
	width: 100%;
	min-height: 58px;
	border: 3px solid #fff;
	border-radius: 10px;
	background: #060618;
	color: #fff;
	font-family: var(--font);
	font-size: 1.4rem;
	text-align: center;
	padding: 8px 14px;
}

#name-input:focus { outline: 3px solid var(--gold); }

.name-hint { color: var(--ink-soft); font-size: 0.85rem; margin: 10px 0 18px; }

#btn-name-ok { width: 100%; font-size: 1.15rem; }

/* ===== マップ ===== */
#screen-map { padding: 12px 12px 16px; gap: 10px; }

#hud {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
}

.hud-chip {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	border: 2px solid rgba(255, 255, 255, 0.7);
	border-radius: 8px;
	background: rgba(10, 10, 34, 0.9);
	padding: 4px 14px;
	font-size: 0.95rem;
}

.hud-chip.hud-name { color: var(--gold); }

.hud-btn {
	margin-left: auto;
	min-height: 48px;
	border: 3px solid var(--gold);
	border-radius: 10px;
	background: #3d2c00;
	color: #ffe9ad;
	font-size: 1rem;
	padding: 6px 16px;
}

.hud-btn:hover { background: #5a4200; }

#map-wrap { position: relative; }

#map-scene {
	position: relative;
	width: 100%;
	aspect-ratio: 16 / 10;
	min-height: 320px;
	border: 3px solid rgba(255, 255, 255, 0.8);
	border-radius: 12px;
	background:
		radial-gradient(circle at 20% 25%, rgba(110, 207, 127, 0.16), transparent 34%),
		radial-gradient(circle at 78% 30%, rgba(110, 207, 127, 0.12), transparent 30%),
		radial-gradient(circle at 55% 75%, rgba(110, 207, 127, 0.14), transparent 36%),
		linear-gradient(180deg, #10173a 0%, #0e2418 100%);
	overflow: hidden;
}

.map-node {
	position: absolute;
	transform: translate(-50%, -50%);
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 2px;
	min-width: 76px;
	min-height: 64px;
	border: 2px solid rgba(255, 255, 255, 0.35);
	border-radius: 10px;
	background: rgba(6, 6, 24, 0.55);
	color: #fff;
	padding: 6px 10px;
	font-family: var(--font);
	transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.map-node .node-icon { font-size: clamp(1.5rem, 4.4vw, 2.1rem); line-height: 1.2; }

.map-node .node-name { font-size: clamp(0.7rem, 2vw, 0.88rem); white-space: nowrap; }

.map-node:hover {
	border-color: #fff;
	background: rgba(27, 27, 70, 0.85);
	transform: translate(-50%, -52%);
}

.map-node.is-target {
	border: 3px solid var(--gold);
	background: rgba(61, 44, 0, 0.75);
	box-shadow: 0 0 18px rgba(246, 185, 26, 0.45);
}

.map-node.is-target::after {
	content: '❗';
	position: absolute;
	top: -34px;
	left: 50%;
	transform: translateX(-50%);
	font-size: 1.5rem;
	animation: bounce 0.9s ease-in-out infinite;
}

@keyframes bounce {
	0%, 100% { transform: translateX(-50%) translateY(0); }
	50% { transform: translateX(-50%) translateY(-8px); }
}

#player-token {
	position: absolute;
	z-index: 5;
	font-size: clamp(1.6rem, 4.6vw, 2.2rem);
	transform: translate(-50%, -50%);
	transition: left 0.7s ease-in-out, top 0.7s ease-in-out;
	filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.6));
	pointer-events: none;
}

#map-hint {
	font-size: 1rem;
	padding: 14px 18px;
	color: var(--ink-soft);
}

#map-hint strong { color: var(--gold); }

/* ===== 会話レイヤー ===== */
#dialog-layer {
	position: fixed;
	inset: 0;
	z-index: 40;
	display: flex;
	flex-direction: column;
	justify-content: flex-end;
	background: rgba(2, 2, 12, 0.72);
}

#dialog-stage {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
}

#dialog-portrait {
	font-size: clamp(4rem, 18vw, 7.5rem);
	line-height: 1;
	filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.6));
	animation: appear 0.25s ease;
}

@keyframes appear {
	from { transform: scale(0.85); opacity: 0; }
	to { transform: scale(1); opacity: 1; }
}

#dialog-bottom {
	width: min(760px, calc(100% - 24px));
	margin: 0 auto 18px;
}

#dialog-window {
	min-height: 150px;
	cursor: pointer;
	user-select: none;
}

#dialog-name {
	position: absolute;
	top: -19px;
	left: 16px;
	border: 2px solid #fff;
	border-radius: 8px;
	background: #1b1b46;
	padding: 2px 14px;
	font-size: 0.95rem;
	color: var(--gold);
}

#dialog-name:empty { display: none; }

#dialog-text {
	font-size: clamp(1.02rem, 2.8vw, 1.18rem);
	line-height: 2;
	min-height: 76px;
	white-space: pre-wrap;
}

#dialog-next {
	text-align: right;
	color: var(--gold);
	font-size: 0.85rem;
	animation: blink 1s steps(2) infinite;
}

#dialog-next[hidden] { display: none; }

@keyframes blink {
	0%, 60% { opacity: 1; }
	61%, 100% { opacity: 0.15; }
}

#dialog-choices {
	display: flex;
	flex-direction: column;
	gap: 10px;
	margin-top: 12px;
}

#dialog-choices .rpg-btn { width: 100%; justify-content: flex-start; text-align: left; }

/* ===== バトル ===== */
#screen-battle {
	position: fixed;
	inset: 0;
	z-index: 40;
	display: flex;
	flex-direction: column;
	background:
		radial-gradient(ellipse at 50% 20%, rgba(120, 40, 80, 0.4), transparent 60%),
		var(--bg-deep);
}

#battle-stage {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
}

#enemy-area {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
	padding-top: 20px;
}

#enemy-sprite {
	font-size: clamp(4.4rem, 20vw, 8rem);
	line-height: 1;
	filter: drop-shadow(0 12px 30px rgba(0, 0, 0, 0.7));
}

#enemy-sprite.hit { animation: hit 0.5s ease; }

@keyframes hit {
	0% { transform: translateX(0); filter: brightness(3); }
	25% { transform: translateX(-14px); }
	50% { transform: translateX(12px); }
	75% { transform: translateX(-8px); }
	100% { transform: translateX(0); }
}

#enemy-sprite.down { animation: down 1s ease forwards; }

@keyframes down {
	to { transform: translateY(30px) scale(0.6); opacity: 0; }
}

#enemy-name { padding: 6px 18px; font-size: 1rem; }

#enemy-hp { display: flex; align-items: center; gap: 10px; }

.hp-label { font-size: 0.8rem; color: var(--ink-soft); }

.hp-bar {
	width: min(300px, 56vw);
	height: 16px;
	border: 2px solid #fff;
	border-radius: 8px;
	background: #240b0b;
	overflow: hidden;
}

#enemy-hp-fill {
	height: 100%;
	width: 100%;
	background: linear-gradient(90deg, #ff6b6b, #ffb36b);
	transition: width 0.5s ease;
}

#battle-bottom {
	width: min(760px, calc(100% - 24px));
	margin: 0 auto 18px;
}

#battle-window { min-height: 110px; }

#battle-question {
	font-size: clamp(1.02rem, 2.8vw, 1.16rem);
	line-height: 2;
	white-space: pre-wrap;
}

#battle-choices {
	display: flex;
	flex-direction: column;
	gap: 10px;
	margin-top: 12px;
}

#battle-choices .rpg-btn {
	width: 100%;
	justify-content: flex-start;
	text-align: left;
	line-height: 1.6;
}

#battle-choices .rpg-btn.correct { background: #114d2a; border-color: var(--accent); }

#battle-choices .rpg-btn.wrong { background: #4d1111; border-color: var(--danger); }

/* ===== 演習パネル ===== */
#screen-exercise {
	position: fixed;
	inset: 0;
	z-index: 45;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(2, 2, 12, 0.8);
	padding: 14px;
	overflow-y: auto;
}

#exercise-panel {
	width: min(680px, 100%);
	max-height: calc(100dvh - 28px);
	overflow-y: auto;
	padding: 24px 22px;
}

#exercise-panel h3 {
	margin: 0 0 6px;
	color: var(--gold);
	font-size: 1.15rem;
}

#exercise-panel .ex-goal {
	margin: 0 0 16px;
	font-size: 1rem;
	color: var(--ink-soft);
}

.ex-compare { display: grid; gap: 12px; }

.ex-group { margin-bottom: 16px; }

.ex-group-label {
	display: inline-block;
	margin-bottom: 8px;
	border: 2px solid var(--gold);
	border-radius: 8px;
	color: var(--gold);
	padding: 1px 12px;
	font-size: 0.88rem;
}

.ex-options { display: grid; gap: 8px; }

.ex-options .rpg-btn {
	min-height: 52px;
	justify-content: flex-start;
	text-align: left;
	font-size: 0.98rem;
	line-height: 1.6;
}

.ex-options .rpg-btn.selected {
	background: #3d2c00;
	border-color: var(--gold);
	color: #ffe9ad;
}

.ex-preview {
	border: 2px dashed rgba(255, 255, 255, 0.5);
	border-radius: 10px;
	background: #060618;
	padding: 14px 16px;
	margin: 14px 0;
	font-size: 1rem;
	line-height: 1.9;
	min-height: 64px;
}

.ex-preview .ph { color: #666a8f; }

.ai-reply {
	display: flex;
	gap: 12px;
	align-items: flex-start;
	border: 2px solid var(--accent);
	border-radius: 10px;
	background: rgba(17, 77, 42, 0.35);
	padding: 14px 16px;
	margin-top: 14px;
	font-size: 1rem;
	line-height: 1.9;
	white-space: pre-wrap;
}

.ai-reply .ai-face { font-size: 1.8rem; line-height: 1.2; }

#exercise-panel textarea {
	width: 100%;
	min-height: 96px;
	border: 3px solid #fff;
	border-radius: 10px;
	background: #060618;
	color: #fff;
	font-family: var(--font);
	font-size: 1.05rem;
	line-height: 1.8;
	padding: 12px 14px;
	resize: vertical;
}

#exercise-panel textarea:focus { outline: 3px solid var(--gold); }

.ex-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin-top: 16px;
}

.ex-actions .rpg-btn { flex: 1; min-width: 150px; }

/* ===== ぼうけんの書 ===== */
#screen-journal {
	position: fixed;
	inset: 0;
	z-index: 50;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(2, 2, 12, 0.85);
	padding: 14px;
}

#journal-panel {
	width: min(720px, 100%);
	max-height: calc(100dvh - 28px);
	overflow-y: auto;
	padding: 22px;
}

.journal-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
}

.journal-head h2 { margin: 0; font-size: 1.3rem; color: var(--gold); }

.journal-lead { color: var(--ink-soft); font-size: 0.92rem; margin: 8px 0 16px; }

.journal-chapter {
	margin: 18px 0 8px;
	color: var(--accent);
	font-size: 0.95rem;
}

.journal-entry {
	border: 2px solid rgba(255, 255, 255, 0.45);
	border-radius: 10px;
	background: rgba(6, 6, 24, 0.6);
	padding: 14px 16px;
	margin-bottom: 10px;
}

.journal-entry h4 {
	margin: 0 0 6px;
	font-size: 1.05rem;
	color: #fff;
}

.journal-entry p { margin: 0; font-size: 0.95rem; line-height: 1.9; color: var(--ink-soft); }

.journal-entry .je-example {
	margin-top: 8px;
	border-left: 3px solid var(--gold);
	padding-left: 10px;
	font-size: 0.9rem;
	color: #ffe9ad;
}

.journal-empty { color: var(--ink-soft); text-align: center; padding: 30px 0; }

/* ===== 学び獲得トースト ===== */
#learn-toast {
	position: fixed;
	inset: 0;
	z-index: 60;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(2, 2, 12, 0.6);
}

.learn-inner {
	text-align: center;
	padding: 26px 34px;
	animation: learnpop 0.4s ease;
	border-color: var(--gold);
}

@keyframes learnpop {
	from { transform: scale(0.8); opacity: 0; }
	to { transform: scale(1); opacity: 1; }
}

.learn-fanfare { margin: 0 0 8px; color: var(--gold); font-size: 1rem; }

#learn-title { margin: 0; font-size: 1.25rem; }

/* ===== エンディング ===== */
#screen-ending {
	position: fixed;
	inset: 0;
	z-index: 55;
	overflow-y: auto;
	background:
		radial-gradient(ellipse at 50% 0%, rgba(246, 185, 26, 0.18), transparent 55%),
		var(--bg-deep);
	padding: 30px 16px 60px;
}

.ending-inner { width: min(680px, 100%); margin: 0 auto; display: grid; gap: 20px; }

.certificate {
	border: 4px double var(--gold);
	border-radius: 12px;
	background: rgba(20, 16, 2, 0.85);
	text-align: center;
	padding: 34px 22px;
}

.certificate .cert-label { color: var(--gold); letter-spacing: 0.3em; font-size: 0.9rem; margin: 0; }

.certificate h2 { font-size: 1.8rem; margin: 12px 0; }

.certificate .cert-name { font-size: 1.5rem; color: var(--gold); margin: 14px 0; }

.certificate p { line-height: 2; }

.next-steps { padding: 22px; }

.next-steps h3 { color: var(--gold); margin: 0 0 10px; }

.next-steps ol { margin: 0; padding-left: 22px; line-height: 2.1; }

.copy-block {
	border: 2px dashed rgba(255, 255, 255, 0.5);
	border-radius: 10px;
	background: #060618;
	padding: 12px 14px;
	margin: 10px 0;
	font-size: 0.95rem;
	line-height: 1.8;
}

.copy-block button { margin-top: 8px; }

/* ===== レスポンシブ ===== */
@media (max-width: 560px) {
	#map-scene { aspect-ratio: 4 / 5; }

	.map-node { min-width: 64px; min-height: 56px; padding: 4px 6px; }

	#hud { gap: 6px; }

	.hud-chip { min-height: 40px; font-size: 0.8rem; padding: 2px 10px; }

	#dialog-text { min-height: 96px; }

	.ex-actions .rpg-btn { min-width: 100%; }
}
