/**
 * Bubblish Hadatai スタイルシート
 * 画像オーバーレイUI版
 */

/* リセット・共通 */
* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

html, body {
	height: 100%;
	font-family: 'Kosugi Maru', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
	background-color: var(--sub-color);
	color: #333;
}

/* エディターモード時、ページ自体のスクロールを防止 */
body.editor-active {
	overflow: hidden;
	position: fixed;
	width: 100%;
	height: 100%;
}

/* 初期画面ラッパー（ヘッダ・フッタ含む） */
.landing-wrapper {
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	background-color: var(--sub-color);
}

/* テーマカラー（hadatai.jp準拠） */
:root {
	--main-color: #636363;
	--sub-color: #ece9e3;
	--link-color: #e07145;
	--hover-color: #ffb866;
	--accent-color: #007bff;
}

/* ドロップゾーン（初期画面・3分割レイアウト） */
.drop-zone {
	flex: 1;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	background-color: var(--sub-color);
	padding: 20px;
	gap: 24px;
}

/* 上ペイン: タイトル */
.landing-header {
	text-align: center;
}

.landing-title {
	font-size: 32px;
	font-weight: 700;
	color: var(--main-color);
	margin-bottom: 8px;
	letter-spacing: 2px;
}

/* 中ペイン: アップロードエリア */
.landing-upload-area {
	flex: 0 0 auto;
}

.upload-box {
	border: 3px dashed var(--main-color);
	border-radius: 16px;
	padding: 40px 60px;
	text-align: center;
	cursor: pointer;
	transition: border-color 0.2s ease, background-color 0.2s ease;
	background-color: rgba(255, 255, 255, 0.5);
}

.upload-box:hover,
.upload-box.dragover {
	border-color: var(--link-color);
	background-color: rgba(224, 113, 69, 0.1);
}

.upload-icon {
	font-size: 64px;
	margin-bottom: 16px;
	opacity: 0.7;
}

.upload-text {
	font-size: 20px;
	font-weight: 700;
	color: var(--main-color);
	margin-bottom: 8px;
}

.upload-subtext {
	font-size: 14px;
	color: #888;
}

.upload-notice {
	font-size: 12px;
	color: #999;
	margin-top: 16px;
}

/* 下ペイン: メッセージ */
.landing-message {
	text-align: left;
	color: var(--main-color);
	font-size: 14px;
	line-height: 1.8;
	max-width: 500px;
}

.landing-message ul {
	list-style: none;
	padding: 0;
	margin: 0;
}

.landing-message li {
	margin: 8px 0;
	padding-left: 1.5em;
	position: relative;
}

.landing-message li::before {
	content: "";
	position: absolute;
	left: 0;
	top: 0.5em;
	width: 6px;
	height: 6px;
	background-color: var(--link-color);
	border-radius: 50%;
}

.landing-message a {
	color: var(--link-color);
	text-decoration: none;
}

.landing-message a:hover {
	color: var(--hover-color);
	text-decoration: underline;
}

.landing-message .welcome-qr {
	font-size: 16px;
	font-weight: bold;
	color: var(--link-color);
	margin-bottom: 16px;
	text-align: center;
}

/* 旧スタイル（互換用） */
.drop-zone-content {
	text-align: center;
	color: #888;
}

.drop-icon {
	font-size: 80px;
	margin-bottom: 20px;
	opacity: 0.6;
}

.drop-text {
	font-size: 24px;
	font-weight: 700;
	color: #ccc;
	margin-bottom: 8px;
}

.drop-subtext {
	font-size: 14px;
	color: #888;
}

/* エディターラッパー（フルスクリーン、スクロール対応） */
.editor-wrapper {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: var(--sub-color);
	overflow: hidden;
}

/* スクロール対応モード */
.editor-wrapper.scrollable {
	overflow: auto;
}

/* エディターコンテナ（画像コンテナ、transformはJSで設定） */
.editor-container {
	position: absolute;
}

/* ベース画像（画面いっぱいに表示） */
.base-image {
	display: block;
	max-width: 100vw;
	max-height: 100vh;
	width: auto;
	height: auto;
	user-select: none;
	-webkit-user-drag: none;
}

/* クリアボタン（右上固定） */
.clear-btn {
	position: fixed;
	top: 16px;
	right: 16px;
	width: 48px;
	height: 48px;
	border: 2px solid rgba(0, 0, 0, 0.2);
	border-radius: 10px;
	background-color: rgba(255, 255, 255, 0.9);
	font-size: 20px;
	cursor: pointer;
	transition: all 0.2s ease;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
	z-index: 1001;
}

.clear-btn:hover {
	background-color: #fff;
	border-color: #c00;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

/* ツールバー（左上オーバーレイ） */
.toolbar {
	position: fixed;
	top: 16px;
	left: 16px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 12px;
	background-color: rgba(99, 99, 99, 0.9);
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
	border-radius: 12px;
	z-index: 1000;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.toolbar-separator {
	height: 1px;
	background-color: rgba(0, 0, 0, 0.15);
	margin: 4px 0;
}

.toolbar-btn {
	width: 48px;
	height: 48px;
	border: 2px solid rgba(0, 0, 0, 0.2);
	border-radius: 10px;
	background-color: rgba(255, 255, 255, 0.9);
	font-size: 24px;
	cursor: pointer;
	transition: all 0.2s ease;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toolbar-btn:hover {
	background-color: #ffffff;
	border-color: var(--link-color);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.toolbar-btn.active {
	background-color: var(--link-color);
	border-color: var(--link-color);
	box-shadow: 0 2px 8px rgba(224, 113, 69, 0.5);
}

.toolbar-btn.disabled,
.toolbar-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	pointer-events: none;
	background-color: rgba(200, 200, 200, 0.7);
}

.toolbar-btn.disabled:hover,
.toolbar-btn:disabled:hover {
	background-color: rgba(200, 200, 200, 0.7);
	border-color: rgba(0, 0, 0, 0.2);
}

/* カラーピッカー */
.color-picker {
	width: 48px;
	height: 48px;
	padding: 4px;
	border: 2px solid rgba(0, 0, 0, 0.2);
	border-radius: 10px;
	cursor: pointer;
	background-color: rgba(255, 255, 255, 0.9);
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.color-picker:hover {
	border-color: var(--link-color);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.color-picker::-webkit-color-swatch-wrapper {
	padding: 2px;
}

.color-picker::-webkit-color-swatch {
	border: none;
	border-radius: 6px;
}

/* ツールバー内のプライマリボタン（保存ボタン用） */
.toolbar-btn-primary {
	background-color: var(--link-color);
	color: white;
	border-color: var(--link-color);
}

.toolbar-btn-primary:hover {
	background-color: var(--hover-color);
	border-color: var(--hover-color);
}

/* デバッグボタン（右上オーバーレイ） */
.debug-buttons {
	position: fixed;
	top: 16px;
	right: 16px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	z-index: 1000;
}

.debug-btn {
	width: 40px;
	height: 40px;
	border: 2px solid rgba(0, 0, 0, 0.2);
	border-radius: 8px;
	background-color: rgba(255, 255, 255, 0.7);
	font-size: 16px;
	cursor: pointer;
	transition: all 0.2s ease;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.debug-btn:hover {
	background-color: #fff;
	border-color: var(--link-color);
}

/* トースト通知 */
.toast-container {
	position: fixed;
	top: 24px;
	left: 50%;
	transform: translateX(-50%);
	z-index: 10000;
	display: flex;
	flex-direction: column;
	gap: 8px;
	align-items: center;
}

.toast {
	display: inline-block;
	width: fit-content;
	padding: 12px 24px;
	background-color: rgba(99, 99, 99, 0.95);
	color: white;
	border-radius: 8px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans CJK JP", sans-serif;
	font-size: 14px;
	font-weight: normal;
	text-align: center;
	opacity: 0;
	transform: translateY(-20px);
	transition: opacity 0.3s ease, transform 0.3s ease;
	white-space: nowrap;
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.toast.show {
	opacity: 1;
	transform: translateY(0);
}

/* レイヤー選択状態 */
.layer-selected {
	outline: 2px solid var(--accent-color);
	outline-offset: 2px;
}

/* リサイズハンドル */
.resize-handle {
	position: absolute;
	width: 24px;
	height: 24px;
	background-color: var(--accent-color);
	border: 3px solid white;
	border-radius: 6px;
	z-index: 10;
}

.resize-handle-nw { top: -12px; left: -12px; cursor: nw-resize; }
.resize-handle-ne { top: -12px; right: -12px; cursor: ne-resize; }
.resize-handle-sw { bottom: -12px; left: -12px; cursor: sw-resize; }
.resize-handle-se { bottom: -12px; right: -12px; cursor: se-resize; }
.resize-handle-n { top: -12px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.resize-handle-s { bottom: -12px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.resize-handle-e { top: 50%; right: -12px; transform: translateY(-50%); cursor: e-resize; }
.resize-handle-w { top: 50%; left: -12px; transform: translateY(-50%); cursor: w-resize; }

/* スマホ用リサイズハンドル（タッチしやすく大きく） */
@media (max-width: 768px) {
	.resize-handle {
		width: 48px;
		height: 48px;
		border-width: 4px;
		border-radius: 12px;
	}

	.resize-handle-nw { top: -24px; left: -24px; }
	.resize-handle-ne { top: -24px; right: -24px; }
	.resize-handle-sw { bottom: -24px; left: -24px; }
	.resize-handle-se { bottom: -24px; right: -24px; }
	.resize-handle-n { top: -24px; }
	.resize-handle-s { bottom: -24px; }
	.resize-handle-e { right: -24px; }
	.resize-handle-w { left: -24px; }
}

/* 吹き出しレイヤー */
.bubble-layer {
	pointer-events: auto;
}

.bubble-layer svg {
	overflow: visible;
}

/* しっぽドラッグハンドル */
.bubble-tail-handle {
	transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.bubble-tail-handle:hover {
	transform: scale(1.2);
	box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
}

/* スマホ用しっぽハンドル（タッチしやすく大きく） */
@media (max-width: 768px) {
	.bubble-tail-handle {
		width: 56px !important;
		height: 56px !important;
		transform: translate(-12px, -12px);  /* JSの-16pxオフセットを補正 */
		border-width: 4px !important;
	}
}

/* テキストレイヤー */
.text-layer {
	writing-mode: vertical-rl;
	text-orientation: upright;
	min-width: 1.5em;
	min-height: 3em;
	padding: 8px;
	cursor: move;
	user-select: none;
	background: transparent;
	white-space: pre-wrap;
	line-height: 1.0;
	font-family: 'Zen Maru Gothic', 'Yu Mincho', 'Hiragino Mincho Pro', serif;
}

.text-layer.editing {
	cursor: text;
	user-select: text;
	outline: 2px dashed var(--accent-color);
	background-color: rgba(255, 255, 255, 0.9);
}

.text-layer:focus {
	outline: 2px dashed var(--accent-color);
}

/* 吹き出しとテキストのz-index管理 */
.bubble-layer { z-index: 100; }
.text-layer { z-index: 200; }

/* レスポンシブ */
@media (max-width: 768px) {
	/* クリアボタンは常に左上固定 */
	.clear-btn {
		width: 40px;
		height: 40px;
		font-size: 16px;
	}

	.toolbar {
		top: auto;
		bottom: 16px;
		left: 16px;
		flex-direction: row;
		flex-wrap: wrap;
		max-width: calc(100% - 32px);
	}

	.toolbar-separator {
		width: 1px;
		height: 32px;
		margin: 0 4px;
	}

	.toolbar-btn {
		width: 40px;
		height: 40px;
		font-size: 20px;
	}

	.color-picker {
		width: 40px;
		height: 40px;
	}

	/* デバッグボタンは右上固定 */
	.debug-btn {
		width: 36px;
		height: 36px;
		font-size: 14px;
	}
}

@media (max-width: 480px) {
	.clear-btn {
		width: 36px;
		height: 36px;
		font-size: 14px;
	}

	.toolbar-btn {
		width: 36px;
		height: 36px;
		font-size: 18px;
	}

	.color-picker {
		width: 36px;
		height: 36px;
	}

	.debug-btn {
		width: 32px;
		height: 32px;
		font-size: 12px;
	}
}

/* フォント選択モーダル */
.font-modal {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: rgba(99, 99, 99, 0.6);
	z-index: 10000;
	display: flex;
	justify-content: center;
	align-items: center;
}

.font-modal-content {
	background-color: #fff;
	border-radius: 12px;
	padding: 20px;
	max-width: 400px;
	width: 90%;
	max-height: 70vh;
	display: flex;
	flex-direction: column;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.font-modal-header {
	font-size: 18px;
	font-weight: bold;
	color: var(--main-color);
	margin-bottom: 16px;
	text-align: center;
}

.font-list {
	flex: 1;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin-bottom: 16px;
}

.font-item {
	padding: 12px 16px;
	background-color: var(--sub-color);
	border-radius: 8px;
	cursor: pointer;
	transition: background-color 0.2s ease;
	color: var(--main-color);
	font-size: 18px;
}

.font-item:hover {
	background-color: #ddd;
}

.font-item.selected {
	background-color: var(--link-color);
	color: #fff;
}

.font-modal-close {
	padding: 12px 24px;
	background-color: var(--sub-color);
	border: none;
	border-radius: 8px;
	color: var(--main-color);
	font-size: 16px;
	cursor: pointer;
	transition: background-color 0.2s ease;
}

.font-modal-close:hover {
	background-color: #ddd;
}

/* カラーピッカーモーダル */
.color-modal-content {
	background-color: #fff;
	border-radius: 12px;
	padding: 20px;
	width: 340px;
	max-height: 80vh;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 16px;
	overflow-y: auto;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.color-picker-large {
	width: 200px;
	height: 150px;
	padding: 0;
	border: 2px solid var(--main-color);
	border-radius: 8px;
	cursor: pointer;
	background: transparent;
}

.color-picker-large::-webkit-color-swatch-wrapper {
	padding: 4px;
}

.color-picker-large::-webkit-color-swatch {
	border: none;
	border-radius: 4px;
}

.color-presets {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	justify-content: center;
	max-width: 300px;
}

.color-preset {
	width: 28px;
	height: 28px;
	border-radius: 4px;
	cursor: pointer;
	border: 2px solid rgba(99, 99, 99, 0.3);
	transition: transform 0.1s ease, border-color 0.1s ease;
}

.color-preset:hover {
	transform: scale(1.15);
	border-color: var(--link-color);
	z-index: 1;
}

.color-modal-buttons {
	display: flex;
	gap: 12px;
	width: 100%;
}

.color-modal-buttons button {
	flex: 1;
}

.color-modal-ok {
	padding: 12px 24px;
	background-color: var(--link-color);
	border: none;
	border-radius: 8px;
	color: #fff;
	font-size: 16px;
	cursor: pointer;
	transition: background-color 0.2s ease;
}

.color-modal-ok:hover {
	background-color: var(--hover-color);
}

/* スクロール対応のエディターラッパー（追加設定） */
.editor-wrapper.scrollable {
	cursor: grab;
	/* スマホでのピンチズーム・自動スケーリングを防止 */
	touch-action: pan-x pan-y;
	-webkit-overflow-scrolling: touch;
}

.editor-wrapper.scrollable .base-image {
	cursor: grab;
}

/* スケール適用時のベース画像（max制約を解除） */
.base-image.scaled {
	max-width: none;
	max-height: none;
}

/* プレビューモード */
.editor-wrapper.preview-mode {
	overflow: hidden;
	cursor: pointer;
	display: flex;
	justify-content: center;
	align-items: center;
}

.editor-wrapper.preview-mode .editor-container {
	position: relative;
	top: auto;
	left: auto;
	transform-origin: center center;
	transition: transform 0.3s ease;
}

/* プレビュー中はツールバーとアクションボタンを非表示 */
.editor-wrapper.preview-mode ~ .toolbar,
.editor-wrapper.preview-mode ~ .action-buttons {
	display: none;
}

/* プレビューオーバーレイ（タップで戻る案内） */
.preview-overlay {
	position: fixed;
	bottom: 20px;
	left: 50%;
	transform: translateX(-50%);
	background-color: rgba(0, 0, 0, 0.7);
	color: white;
	padding: 12px 24px;
	border-radius: 8px;
	font-size: 14px;
	z-index: 10000;
	pointer-events: none;
}

/* デバッグログパネル */
.log-panel {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	height: 40vh;
	background-color: rgba(0, 0, 0, 0.9);
	color: #0f0;
	font-family: monospace;
	font-size: 11px;
	z-index: 20000;
	display: flex;
	flex-direction: column;
}

.log-panel-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 8px 12px;
	background-color: #333;
	color: white;
	font-size: 14px;
}

.log-clear-btn {
	background-color: #666;
	color: white;
	border: none;
	padding: 4px 12px;
	border-radius: 4px;
	margin-right: 8px;
	cursor: pointer;
}

.log-close-btn {
	background-color: #c00;
	color: white;
	border: none;
	width: 28px;
	height: 28px;
	border-radius: 4px;
	font-size: 18px;
	cursor: pointer;
}

.log-content {
	flex: 1;
	overflow-y: auto;
	padding: 8px;
	white-space: pre-wrap;
	word-break: break-all;
}

