/* RETOMO - ガラケー風レトロチャット CSS */
/* ウィルコム/PHS級の粗い画質感を狙う */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
  overflow: hidden;
  height: 100%;
}

body {
  font-family: "DotGothic16", "M PLUS 1 Code", "Courier New", monospace;
  background: #1a1a1a;
  height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 0;
  color: #fff;
  /* アンチエイリアス抑制でピクセル感を強調 */
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: grayscale;
  font-smooth: never;
  -webkit-touch-callout: none;
  user-select: none;
  /* ブラウザのスワイプ・スクロール無効 */
  overscroll-behavior: none;
  touch-action: manipulation;
  overflow: hidden;
}

/* テキスト入力フィールドだけは選択可 */
.text-input, textarea, .code-display, .msg-text {
  user-select: text;
  -webkit-user-select: text;
}

/* ========================================
   テーマ変数（3パターン）
   ======================================== */

/* あお（青みがかった白LCD、紺色文字、シルバー筐体） */
body.theme-willcom {
  --lcd-0: #b8d0e8;
  --lcd-1: #2050a0;
  --lcd-2: #0028a0;
  --lcd-3: #000040;
  --warn: #e02020;
  --device-body: #6a7484;
  --device-shadow: rgba(0,0,0,0.5);
  --key-body: #555a64;
  --key-text: #ddd;
  --key-shadow: #222;
}

/* あか（暖色系・原色） */
body.theme-red {
  --lcd-0: #f4d8d8;
  --lcd-1: #c02020;
  --lcd-2: #a00000;
  --lcd-3: #400000;
  --warn: #ff8800;
  --device-body: #7a5050;
  --device-shadow: rgba(0,0,0,0.5);
  --key-body: #604040;
  --key-text: #fce8e8;
  --key-shadow: #200;
}

/* むらさき（紫・原色） */
body.theme-purple {
  --lcd-0: #e0d0f0;
  --lcd-1: #6020a0;
  --lcd-2: #400080;
  --lcd-3: #200040;
  --warn: #e02020;
  --device-body: #5a4880;
  --device-shadow: rgba(0,0,0,0.5);
  --key-body: #483868;
  --key-text: #e8d8f8;
  --key-shadow: #110028;
}

/* カスタム（ユーザー設定） */
body.theme-custom {
  /* JS で --lcd-0 〜 --warn を上書き */
  --device-body: #555;
  --device-shadow: rgba(0,0,0,0.5);
  --key-body: #444;
  --key-text: #ddd;
  --key-shadow: #222;
}

body.theme-green {
  --lcd-0: #0f380f;
  --lcd-1: #306230;
  --lcd-2: #8bac0f;
  --lcd-3: #9bbc0f;
  --warn: #ff6b6b;
  --device-body: #2a2a2a;
  --device-shadow: rgba(0,0,0,0.5);
  --key-body: #444;
  --key-text: #ccc;
  --key-shadow: #222;
}

body.theme-mono {
  --lcd-0: #e8e0c0;
  --lcd-1: #9c9078;
  --lcd-2: #3a3528;
  --lcd-3: #000000;
  --warn: #cc2222;
  --device-body: #1a1a1a;
  --device-shadow: rgba(0,0,0,0.6);
  --key-body: #3a3a3a;
  --key-text: #ddd;
  --key-shadow: #111;
}

body.theme-orange {
  --lcd-0: #1a0800;
  --lcd-1: #552200;
  --lcd-2: #ff7700;
  --lcd-3: #ffaa00;
  --warn: #ff5050;
  --device-body: #2a2018;
  --device-shadow: rgba(0,0,0,0.5);
  --key-body: #443830;
  --key-text: #ccb;
  --key-shadow: #110;
}

/* ========================================
   物理デバイス風フレーム
   ======================================== */

.device {
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  background: var(--device-body);
  border-radius: 0;
  padding:
    calc(env(safe-area-inset-top) + 10px)
    calc(env(safe-area-inset-right) + 10px)
    calc(env(safe-area-inset-bottom) + 10px)
    calc(env(safe-area-inset-left) + 10px);
  box-shadow: none;
  position: relative;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

/* PC 等の広い画面では程よい幅に制約 */
@media (min-width: 600px) {
  .device {
    max-width: 420px;
    height: 100vh;
    border-radius: 28px;
    margin: 0;
    box-shadow:
      0 8px 24px var(--device-shadow),
      inset 0 1px 0 rgba(255,255,255,0.1);
  }
}

.device-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 6px 8px 10px;
  position: relative;
  margin-bottom: 4px;
}

/* フロントカメラ（小さい黒い丸 + 内側の薄いハイライト） */
.front-camera {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: radial-gradient(circle at 30% 30%, #555 0%, #111 60%, #000 100%);
  border-radius: 50%;
  box-shadow: inset 0 0 1px rgba(255,255,255,0.4), 0 0 1px rgba(0,0,0,0.6);
  flex-shrink: 0;
}

/* 点々スピーカー（小さい丸が並ぶ） */
.speaker-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}
.speaker-dots span {
  width: 3px;
  height: 3px;
  background: radial-gradient(circle, #111 0%, #000 70%);
  border-radius: 50%;
  display: inline-block;
}

.device-top-spacer {
  display: inline-block;
  width: 8px;
}

/* ========================================
   仮想LCD画面
   ======================================== */

/* LCD を囲む窓枠（薄青のベゼル）— 画面いっぱい */
.lcd-window {
  width: 100%;
  flex: 1;
  min-height: 0;
  margin: 0;
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--device-body) 60%, #cad8e8) 0%,
    color-mix(in srgb, var(--device-body) 40%, #cad8e8) 100%);
  border-radius: 12px;
  padding: 8px;
  box-shadow:
    inset 0 1px 2px rgba(255,255,255,0.25),
    inset 0 -1px 1px rgba(0,0,0,0.15),
    0 0 0 1px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
}

.lcd {
  width: 100%;
  flex: 1;
  min-height: 0;
  aspect-ratio: auto; /* 画面いっぱい時は比率制約を外す */
  background: var(--lcd-0);
  border: 2px solid var(--lcd-1);
  border-radius: 8px;
  padding: 8px;
  position: relative;
  overflow: hidden;
  color: var(--lcd-2);
  /* LCD グレア風の微小グラデ */
  box-shadow:
    inset 0 0 20px rgba(0,0,0,0.15),
    0 1px 0 rgba(255,255,255,0.08);
  box-sizing: border-box;
}

/* 窓枠の中、LCD の下に小さく RETOMO */
.lcd-window-brand {
  width: 100%;
  padding: 4px 0 2px;
  text-align: center;
}
.lcd-window-brand .device-brand-text {
  font-size: 10px;
  letter-spacing: 4px;
  color: rgba(255,255,255,0.55);
  text-shadow: 0 1px 0 rgba(0,0,0,0.3);
  font-weight: bold;
}

/* LCD 内ステータスバー (電波・時刻・バッテリー) */
.lcd-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 4px;
  font-size: 10px;
  color: var(--lcd-2);
  border-bottom: 1px solid var(--lcd-1);
  margin-bottom: 4px;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  font-feature-settings: "tnum";
}
.status-signal {
  display: flex;
  gap: 1px;
  align-items: flex-end;
  height: 9px;
}
.status-signal span {
  width: 2px;
  background: var(--lcd-2);
  display: block;
}
.status-signal span:nth-child(1) { height: 3px; }
.status-signal span:nth-child(2) { height: 5px; }
.status-signal span:nth-child(3) { height: 7px; }
.status-signal span:nth-child(4) { height: 9px; }
.status-signal.weak span:nth-child(3),
.status-signal.weak span:nth-child(4) { opacity: 0.25; }
.status-signal.offline span { opacity: 0.15; }
.status-time {
  font-size: 11px;
  color: var(--lcd-3);
  letter-spacing: 1px;
}
.status-battery {
  display: inline-block;
  width: 18px;
  height: 9px;
  border: 1px solid var(--lcd-2);
  position: relative;
}
.status-battery::after {
  content: "";
  position: absolute;
  right: -3px;
  top: 2px;
  width: 2px;
  height: 5px;
  background: var(--lcd-2);
}
.battery-fill {
  display: block;
  height: 100%;
  background: var(--lcd-2);
  width: 80%;
}
.battery-fill.low { background: var(--warn); width: 20%; }

/* 旧 RETOMO ロゴ枠（使用してないが念のため非表示にしない・他で残骸ある場合のフォールバック） */
.device-brand-frame { display: none; }

/* スキャンライン演出 (任意、軽め) */
.lcd::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent 0,
    transparent 3px,
    rgba(0,0,0,0.05) 3px,
    rgba(0,0,0,0.05) 4px
  );
  pointer-events: none;
}

body.theme-mono .lcd::after,
body.theme-willcom .lcd::after {
  background: repeating-linear-gradient(
    0deg,
    transparent 0,
    transparent 3px,
    rgba(0,0,0,0.07) 3px,
    rgba(0,0,0,0.07) 4px
  );
}

/* 画面切替 — ステータスバーの分だけ上を下げる */
.screen {
  position: absolute;
  left: 6px;
  right: 6px;
  top: 24px;
  bottom: 6px;
  display: none;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

.screen-title {
  font-size: 14px;
  color: var(--lcd-3);
  border-bottom: 1px dashed var(--lcd-1);
  padding-bottom: 4px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-shrink: 0;
}

.screen-body {
  flex: 1;
  overflow-y: auto;
  padding-right: 2px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  line-height: 1.5;
  /* スクロールバーをピクセル感に */
  scrollbar-width: thin;
  scrollbar-color: var(--lcd-2) var(--lcd-0);
}

.screen-body::-webkit-scrollbar {
  width: 6px;
}
.screen-body::-webkit-scrollbar-track {
  background: var(--lcd-0);
}
.screen-body::-webkit-scrollbar-thumb {
  background: var(--lcd-2);
}

.screen-body.center {
  justify-content: center;
  align-items: center;
  text-align: center;
}

/* ========================================
   メニュー
   ======================================== */

.menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu-item {
  background: transparent;
  border: none;
  color: var(--lcd-2);
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  padding: 8px 4px;
  display: flex;
  gap: 8px;
  align-items: center;
  cursor: pointer;
  width: 100%;
}

.menu-item:hover,
.menu-item:focus {
  background: var(--lcd-1);
  color: var(--lcd-3);
  outline: none;
}

.menu-num {
  display: inline-block;
  width: 18px;
  height: 18px;
  text-align: center;
  border: 1px solid var(--lcd-2);
  color: var(--lcd-3);
  font-size: 11px;
  line-height: 16px;
  flex-shrink: 0;
}

.menu-label {
  flex: 1;
}

/* ========================================
   フォーム
   ======================================== */

.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 4px;
}

.form-row label {
  font-size: 12px;
  color: var(--lcd-3);
}

.form-hint {
  font-size: 11px;
  color: var(--lcd-1);
  opacity: 0.8;
}

.form-err {
  font-size: 12px;
  color: var(--warn);
  min-height: 14px;
}

.text-input {
  background: var(--lcd-0);
  border: 2px solid var(--lcd-1);
  color: var(--lcd-3);
  font-family: inherit;
  font-size: 14px;
  padding: 6px 8px;
  width: 100%;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
}

.text-input:focus {
  border-color: var(--lcd-2);
  outline: none;
}

.text-input.mono {
  letter-spacing: 2px;
  text-align: center;
  font-size: 16px;
}

textarea#chat-input {
  background: var(--lcd-0);
  border: 2px solid var(--lcd-1);
  color: var(--lcd-3);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  width: 100%;
  resize: none;
  border-radius: 0;
}

textarea#chat-input:focus {
  border-color: var(--lcd-2);
  outline: none;
}

textarea#chat-input.emoji-warn {
  border-color: var(--warn);
  animation: shake 0.2s linear;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}

.picker {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  background: var(--lcd-0);
  border: 2px solid var(--lcd-1);
  padding: 4px 8px;
}

.picker-btn {
  background: transparent;
  border: none;
  color: var(--lcd-3);
  font-family: inherit;
  font-size: 16px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.picker-btn:hover,
.picker-btn:focus {
  background: var(--lcd-1);
  outline: none;
}

.picker-val {
  flex: 1;
  text-align: center;
  font-size: 14px;
  color: var(--lcd-3);
}

.check-row {
  flex-direction: column;
}

.check-label {
  display: flex;
  gap: 6px;
  align-items: center;
  cursor: pointer;
  font-size: 13px;
}

.check-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--lcd-3);
}

/* ボタン */
.form-actions {
  display: flex;
  gap: 4px;
  margin-top: auto;
  padding-top: 8px;
  flex-shrink: 0;
}

.btn-primary,
.btn-secondary {
  flex: 1;
  background: var(--lcd-1);
  color: var(--lcd-3);
  border: 2px solid var(--lcd-2);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 0;
}

.btn-primary {
  background: var(--lcd-2);
  color: var(--lcd-0);
  border-color: var(--lcd-3);
}

.btn-primary:hover,
.btn-primary:focus,
.btn-secondary:hover,
.btn-secondary:focus {
  filter: brightness(1.2);
  outline: none;
}

.btn-tiny {
  background: transparent;
  border: 1px solid var(--lcd-1);
  color: var(--lcd-2);
  font-family: inherit;
  font-size: 11px;
  padding: 3px 6px;
  cursor: pointer;
}

.btn-tiny:hover,
.btn-tiny:focus {
  background: var(--lcd-1);
  color: var(--lcd-3);
  outline: none;
}

.btn-send {
  background: var(--lcd-2);
  color: var(--lcd-0);
  border: 2px solid var(--lcd-3);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.text-link {
  color: var(--lcd-3);
  text-decoration: underline;
  font-size: 13px;
}

.theme-row {
  display: flex;
  gap: 4px;
}

.theme-btn {
  flex: 1;
  background: var(--lcd-0);
  border: 2px solid var(--lcd-1);
  color: var(--lcd-2);
  font-family: inherit;
  font-size: 12px;
  padding: 5px 4px;
  cursor: pointer;
}

.theme-btn.selected {
  background: var(--lcd-1);
  color: var(--lcd-3);
  border-color: var(--lcd-3);
}

/* ========================================
   起動 / エラー画面
   ======================================== */

.logo-mark {
  color: var(--lcd-2);
  margin-bottom: 12px;
}

.boot-msg {
  font-size: 14px;
  color: var(--lcd-3);
  margin: 4px 0;
}

.boot-sub {
  font-size: 11px;
  color: var(--lcd-2);
  opacity: 0.8;
}

.err-big {
  font-size: 14px;
  color: var(--warn);
  margin-bottom: 8px;
}

.err-sub {
  font-size: 12px;
  color: var(--lcd-2);
  margin-bottom: 12px;
}

.err-hint {
  font-size: 11px;
  color: var(--lcd-1);
}

/* ========================================
   コード表示 / 広告
   ======================================== */

.result-label {
  font-size: 12px;
  color: var(--lcd-2);
  margin-bottom: 8px;
}

.code-display {
  font-size: 28px;
  letter-spacing: 4px;
  color: var(--lcd-3);
  background: var(--lcd-0);
  border: 2px dashed var(--lcd-2);
  padding: 8px 12px;
  margin: 8px 0;
  word-break: break-all;
  line-height: 1.2;
  /* ピクセル感 */
  font-feature-settings: "tnum";
}

.code-display.save-code {
  font-size: 18px;
  letter-spacing: 2px;
}

.result-meta {
  font-size: 12px;
  color: var(--lcd-2);
}

.meiwa-label {
  font-size: 11px;
  color: var(--lcd-1);
  margin-top: 8px;
}

.meiwa-row {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

.meiwa-text {
  font-size: 13px;
  color: var(--lcd-3);
}

.warn-msg {
  font-size: 12px;
  color: var(--warn);
  margin-top: 8px;
}

.warn-hint {
  font-size: 10px;
  color: var(--lcd-1);
  margin-bottom: 8px;
}

.ad-box {
  border: 2px solid var(--lcd-2);
  padding: 20px 12px;
  text-align: center;
  width: 100%;
  background: var(--lcd-0);
}

.ad-tag {
  font-size: 10px;
  color: var(--lcd-1);
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.ad-msg {
  font-size: 14px;
  color: var(--lcd-3);
  margin-bottom: 4px;
}

.ad-sub {
  font-size: 10px;
  color: var(--lcd-1);
  margin-bottom: 16px;
}

.ad-counter {
  font-size: 12px;
  color: var(--lcd-2);
  border-top: 1px dashed var(--lcd-1);
  padding-top: 8px;
}

#ad-sec {
  color: var(--lcd-3);
  font-size: 14px;
  font-weight: bold;
}

.big-msg {
  font-size: 16px;
  color: var(--lcd-3);
  margin-bottom: 8px;
}

.prompt-msg {
  font-size: 13px;
  color: var(--lcd-2);
  margin-bottom: 8px;
}

/* ========================================
   チャット画面
   ======================================== */

.chat-header {
  font-size: 11px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  align-items: baseline;
}

.chat-room {
  font-size: 12px;
  color: var(--lcd-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-people,
.chat-timer {
  font-size: 11px;
  color: var(--lcd-2);
  font-feature-settings: "tnum";
}

.chat-timer.danger {
  color: var(--warn);
  animation: blink 0.5s linear infinite;
}

@keyframes blink {
  50% { opacity: 0.3; }
}

.chat-body {
  gap: 0;
  padding-right: 0;
}

.msg-list {
  flex: 1;
  list-style: none;
  overflow-y: auto;
  padding: 4px 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg {
  font-size: 12px;
  line-height: 1.4;
  padding: 2px 0;
  border-bottom: 1px dotted var(--lcd-1);
}

.msg.system {
  color: var(--lcd-1);
  font-style: italic;
  text-align: center;
  font-size: 11px;
}

.msg-meta {
  display: flex;
  gap: 4px;
  font-size: 10px;
  color: var(--lcd-1);
  margin-bottom: 2px;
}

.msg-from {
  color: var(--lcd-3);
  font-weight: bold;
}

.msg-time {
  color: var(--lcd-1);
}

.msg-text {
  color: var(--lcd-2);
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-text a {
  color: var(--lcd-3);
  text-decoration: underline;
  word-break: break-all;
}

.farewell-banner {
  border: 2px dashed var(--warn);
  background: var(--lcd-0);
  padding: 6px;
  margin: 4px 0;
  text-align: center;
  animation: blink-soft 1s linear infinite;
}

@keyframes blink-soft {
  50% { opacity: 0.5; }
}

.farewell-title {
  font-size: 12px;
  color: var(--warn);
  font-weight: bold;
}

.farewell-sub {
  font-size: 10px;
  color: var(--lcd-2);
}

.chat-input-area {
  border-top: 1px dashed var(--lcd-1);
  padding-top: 4px;
  margin-top: 4px;
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
  gap: 6px;
}

.chat-input-hint {
  font-size: 10px;
  color: var(--lcd-1);
  flex: 1;
}

.chat-input-hint.warn {
  color: var(--warn);
}

.chat-actions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  flex-shrink: 0;
}

.chat-body.readonly {
  /* 思い出再生時 */
}

.readonly-note {
  font-size: 11px;
  color: var(--lcd-1);
  text-align: center;
  border-bottom: 1px dashed var(--lcd-1);
  padding-bottom: 4px;
  margin-bottom: 4px;
}

/* ========================================
   思い出宝庫
   ======================================== */

.meiwa-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0;
  max-height: 100px;
  overflow-y: auto;
  font-size: 11px;
  color: var(--lcd-2);
  margin-bottom: 4px;
}

.meiwa-list li {
  padding: 2px 4px;
  border-bottom: 1px dotted var(--lcd-1);
  cursor: pointer;
}

.meiwa-list li:hover {
  background: var(--lcd-1);
  color: var(--lcd-3);
}

/* ========================================
   アバウト
   ======================================== */

.about-text {
  font-size: 12px;
  color: var(--lcd-2);
  margin-bottom: 6px;
  line-height: 1.6;
}

.about-version {
  font-size: 10px;
  color: var(--lcd-1);
  text-align: right;
  margin-top: 8px;
}

/* ========================================
   トースト
   ======================================== */

.toast {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--lcd-2);
  color: var(--lcd-0);
  padding: 6px 12px;
  font-size: 12px;
  z-index: 100;
  border: 2px solid var(--lcd-3);
  max-width: 90%;
  text-align: center;
}

.toast.warn {
  background: var(--warn);
  color: #fff;
  border-color: #fff;
}

/* ポケベル風画面内通知バナー */
.pager-banner {
  position: absolute;
  top: 28px;
  left: 4px;
  right: 4px;
  background: var(--lcd-3);
  color: var(--lcd-0);
  border: 2px solid var(--lcd-2);
  padding: 4px 6px;
  font-size: 11px;
  z-index: 200;
  display: flex;
  gap: 4px;
  align-items: center;
  animation: pager-in 0.3s ease-out;
}
.pager-banner.pager-shake {
  animation: pager-in 0.3s ease-out, pager-shake 0.5s ease-in-out 0.3s 2;
}
.pager-icon {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--lcd-0);
}
.pager-from {
  font-weight: bold;
  flex-shrink: 0;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pager-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@keyframes pager-in {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes pager-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* ========================================
   物理キー: 全部非表示（タッチ操作前提）
   ======================================== */

.device-keys {
  display: none;
}

.device-keys-hidden-placeholder {
  margin-top: 8px;
  padding: 4px 4px 6px;
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  grid-template-rows: auto auto;
  gap: 8px 8px;
  align-items: center;
  justify-items: center;
  width: 100%;
}

.key {
  background: var(--key-body);
  border: none;
  color: var(--key-text);
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.18),
    inset 0 -1px 0 rgba(0,0,0,0.18),
    0 1px 2px var(--key-shadow);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  padding: 4px 2px;
}

.key:active {
  transform: translateY(1px);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.3);
}

.key-label {
  font-size: 8px;
  letter-spacing: 0;
  line-height: 1;
}

/* 四隅の機能キー */
.key-corner {
  width: 56px;
  height: 38px;
  border-radius: 8px;
}

.key-tl { grid-column: 1; grid-row: 1; justify-self: center; }
.key-tr { grid-column: 3; grid-row: 1; justify-self: center; }
.key-bl { grid-column: 1; grid-row: 2; justify-self: center; }
.key-br { grid-column: 3; grid-row: 2; justify-self: center; }

.key-menu {
  background: var(--lcd-2);
  color: var(--lcd-0);
  font-weight: bold;
}
.key-menu .key-label {
  font-size: 9px;
  letter-spacing: 1px;
}

/* 円形十字キーパッド (CSS Grid で位置を厳密に) */
.key-pad {
  grid-column: 2;
  grid-row: 1 / 3;
  width: 124px;
  height: 124px;
  position: relative;
  z-index: 2;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--key-body) 0%, var(--key-shadow) 100%);
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.18),
    inset 0 -2px 4px rgba(0,0,0,0.25),
    0 2px 4px rgba(0,0,0,0.3);
  border: none;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  padding: 6px;
  box-sizing: border-box;
}

/* 各方向ボタン共通 */
.key-pad button {
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--key-text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
}

.key-pad button:active {
  background: rgba(0,0,0,0.2);
  transform: none;
}

/* グリッド配置: 3x3 のセルに方向キーと OK を配置 */
.key-pad-up    { grid-column: 2; grid-row: 1; }
.key-pad-left  { grid-column: 1; grid-row: 2; }
.key-pad-ok    { grid-column: 2; grid-row: 2; }
.key-pad-right { grid-column: 3; grid-row: 2; }
.key-pad-down  { grid-column: 2; grid-row: 3; }

/* 中央 OK ボタン */
.key-pad-ok {
  background: var(--warn) !important;
  color: #fff !important;
  font-weight: bold;
  font-size: 13px;
  box-shadow:
    inset 0 2px 3px rgba(255,255,255,0.25),
    inset 0 -2px 3px rgba(0,0,0,0.25),
    0 2px 3px rgba(0,0,0,0.35) !important;
  border: none !important;
  align-self: center;
  justify-self: center;
  width: 44px;
  height: 44px;
  position: relative;
  z-index: 3;
}

.key-pad-ok:active {
  background: var(--lcd-3) !important;
  transform: translateY(1px) !important;
}

/* 物理キーは常に表示（デスクトップでもクリックで操作できるように） */

/* 小型端末向け */
@media (max-height: 700px) and (pointer: coarse) {
  .device {
    max-width: 320px;
    padding: 8px;
  }
  .key-pad {
    width: 116px;
    height: 116px;
  }
  .key-pad-ok {
    width: 40px;
    height: 40px;
  }
  .key-fn {
    height: 32px;
    font-size: 8px;
  }
}

/* デスクトップでも操作しやすく LCD 大きめ */
@media (min-width: 768px) {
  .device {
    max-width: 380px;
  }
  .screen-body {
    font-size: 14px;
  }
}

/* アクセシビリティ: prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* フォーカス可視（キーボード操作時のみ強調） */
:focus-visible {
  outline: 2px solid var(--lcd-3);
  outline-offset: 1px;
}

/* ========================================
   MENU タイル形式（v2.2）
   ======================================== */

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  margin-top: 4px;
}

.menu-tile {
  background: transparent;
  border: none;
  color: var(--tile-color, var(--lcd-2));
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  font-size: 11px;
  line-height: 1.2;
  transition: none;
  aspect-ratio: 1.2 / 1;
}

.menu-tile .menu-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  background: var(--tile-color, var(--lcd-2));
  color: var(--lcd-0);
  border-radius: 10px;
  flex-shrink: 0;
}
.menu-tile .menu-icon svg {
  width: 44px;
  height: 44px;
}
.menu-tile .menu-label {
  font-size: 11px;
  color: var(--lcd-2);
  font-weight: bold;
}

/* ホバーは何もしない（気持ち悪いと指摘あり） */
.menu-tile:hover,
.menu-tile:focus,
.menu-tile:focus-visible {
  outline: none;
}

/* 十字キーフォーカス（JS が付与する .dpad-focused クラス） */
.menu-tile.dpad-focused .menu-icon {
  transform: scale(1.12);
  filter: brightness(1.15);
}
.menu-tile.dpad-focused .menu-label {
  color: var(--lcd-3);
  font-weight: bold;
}
/* 下に小さなインジケータ（黒枠ではなく、選択マーカー的なドット） */
.menu-tile.dpad-focused::after {
  content: "";
  display: block;
  width: 16px;
  height: 3px;
  background: var(--lcd-3);
  border-radius: 2px;
  margin-top: 2px;
}

/* グローバル: フォーカスしたボタンに見える枠（dpad-focused または focus-visible） */
.screen.active .dpad-focused:not(.menu-tile),
.screen.active button:focus-visible,
.screen.active input:focus-visible,
.screen.active textarea:focus-visible,
.screen.active a:focus-visible {
  outline: 3px solid var(--lcd-3);
  outline-offset: 2px;
}

/* 十字キーで選択された入力欄（OK 押下でキーボード起動する前の選択状態） */
.screen.active input.dpad-focused:not(:focus),
.screen.active textarea.dpad-focused:not(:focus) {
  outline: 3px dashed var(--lcd-3);
  outline-offset: 2px;
  background: var(--lcd-0);
}
/* 入力欄が dpad-focused でも OK 押下後に focus されると、上の dashed → solid */
.screen.active input.dpad-focused:focus,
.screen.active textarea.dpad-focused:focus {
  outline: 3px solid var(--lcd-3);
}

.menu-tile.color-1 { --tile-color: #e02020; }
.menu-tile.color-2 { --tile-color: #20a060; }
.menu-tile.color-3 { --tile-color: #c08020; }
.menu-tile.color-4 { --tile-color: #2070d0; }
.menu-tile.color-5 { --tile-color: #6020a0; }
.menu-tile.color-6 { --tile-color: #404858; }
.menu-tile.color-7 { --tile-color: #d04080; }
.menu-tile.color-8 { --tile-color: #208080; }

/* ========================================
   カスタム色ピッカー
   ======================================== */

.preset-color-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin-bottom: 6px;
}

.body-color-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
.body-color-btn {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid #000;
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.3), 0 1px 2px rgba(0,0,0,0.3);
}
.body-color-btn:hover,
.body-color-btn:focus {
  outline: 2px solid var(--lcd-3);
  outline-offset: 2px;
}
.body-color-btn.selected {
  outline: 2px solid var(--lcd-3);
  outline-offset: 2px;
  transform: scale(0.95);
}

.preset-color-btn {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid #000;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.3), 0 1px 2px rgba(0,0,0,0.3);
}
.preset-color-btn:hover,
.preset-color-btn:focus {
  outline: 2px solid var(--lcd-3);
  outline-offset: 2px;
}
.preset-color-btn.selected {
  outline: 2px solid var(--lcd-3);
  outline-offset: 2px;
  transform: scale(0.95);
}

.custom-color-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.custom-color-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--lcd-2);
}

.custom-color-label > span {
  flex: 1;
}

.color-picker {
  width: 32px;
  height: 24px;
  border: 1px solid var(--lcd-1);
  background: transparent;
  padding: 0;
  cursor: pointer;
}

/* ========================================
   メモ
   ======================================== */

.memo-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 0;
  flex: 1;
  overflow-y: auto;
}

.memo-list-item {
  background: var(--lcd-0);
  border: 1px solid var(--lcd-1);
  padding: 6px 8px;
  cursor: pointer;
  font-size: 12px;
}

.memo-list-item:hover,
.memo-list-item:focus {
  background: var(--lcd-1);
  color: var(--lcd-3);
  outline: none;
}

.memo-list-item-title {
  color: var(--lcd-3);
  font-weight: bold;
  margin-bottom: 2px;
}

.memo-list-item-body {
  color: var(--lcd-2);
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memo-list-item-meta {
  color: var(--lcd-1);
  font-size: 9px;
  margin-top: 2px;
}

.memo-list-empty {
  text-align: center;
  color: var(--lcd-1);
  padding: 16px;
}

.memo-body-input {
  min-height: 120px;
  resize: vertical;
}

/* ========================================
   メール
   ======================================== */

.mail-addr-row {
  display: flex;
  align-items: center;
  gap: 2px;
}
.mail-addr-row .text-input {
  flex: 1;
}
.mail-addr-domain {
  font-size: 11px;
  color: var(--lcd-1);
  white-space: nowrap;
}

.mail-tab-row {
  display: flex;
  gap: 2px;
  margin-bottom: 4px;
}

.mail-tab {
  flex: 1;
}

.mail-tab.selected {
  background: var(--lcd-2);
  color: var(--lcd-0);
}

.mail-view-head {
  background: var(--lcd-0);
  border: 1px solid var(--lcd-1);
  padding: 4px 6px;
  margin-bottom: 4px;
  font-size: 11px;
}
.mail-view-row {
  padding: 1px 0;
  color: var(--lcd-2);
  word-break: break-all;
}
.mail-view-label {
  color: var(--lcd-1);
  margin-right: 4px;
}
.mail-view-body {
  flex: 1;
  background: var(--lcd-0);
  border: 1px solid var(--lcd-1);
  padding: 6px;
  overflow-y: auto;
  font-size: 12px;
  color: var(--lcd-2);
  white-space: pre-wrap;
  word-break: break-word;
}

.mail-list-item.unread {
  border-left: 3px solid var(--warn);
}
.mail-list-item-unread-tag {
  color: var(--warn);
  font-size: 9px;
  margin-left: 4px;
}

/* ========================================
   v2: チャットツール / タスク / ウィジェット
   ======================================== */

.chat-tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  margin-top: 2px;
  flex-shrink: 0;
}
.chat-tool {
  padding: 4px 2px;
  font-size: 11px;
  white-space: nowrap;
}
.chat-tool-leave {
  color: var(--warn);
  border-color: var(--warn);
}
.chat-tool-leave:hover,
.chat-tool-leave:focus {
  background: var(--warn);
  color: var(--lcd-0);
}

.task-toggle-label {
  display: flex;
  gap: 2px;
  align-items: center;
  font-size: 10px;
  color: var(--lcd-2);
}

.task-toggle-label input[type="checkbox"] {
  width: 12px;
  height: 12px;
  accent-color: var(--lcd-3);
}

/* タスクメッセージ */
.msg-task {
  border-left: 2px solid var(--lcd-3);
  padding-left: 4px;
}

.task-msg {
  display: flex;
  gap: 6px;
  align-items: flex-start;
}

.task-check {
  background: var(--lcd-0);
  border: 2px solid var(--lcd-2);
  color: var(--lcd-3);
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.task-check.done {
  background: var(--lcd-2);
  color: var(--lcd-0);
}

.task-check:disabled {
  cursor: default;
}

.task-body {
  flex: 1;
  min-width: 0;
}

.task-meta {
  font-size: 10px;
  color: var(--lcd-1);
}

.task-done-tag {
  color: var(--lcd-3);
}

.task-text {
  font-size: 12px;
  color: var(--lcd-2);
  word-break: break-word;
  white-space: pre-wrap;
}

.task-text.done {
  text-decoration: line-through;
  opacity: 0.6;
}

/* 写真メッセージ */
.msg-photo img,
.msg-draw img {
  max-width: 200px;
  border: 2px solid var(--lcd-1);
  image-rendering: pixelated;
  background: var(--lcd-0);
}

/* ウィジェット (ポケベル風) */
.widget-display {
  background: var(--lcd-0);
  border: 2px solid var(--lcd-1);
  padding: 8px;
  min-height: 100px;
  font-size: 12px;
}

.widget-head {
  font-size: 10px;
  color: var(--lcd-1);
  border-bottom: 1px dashed var(--lcd-1);
  padding-bottom: 2px;
  margin-bottom: 4px;
}

.widget-time {
  font-size: 11px;
  color: var(--lcd-2);
}

.widget-kind {
  font-size: 12px;
  color: var(--lcd-3);
  margin-top: 4px;
  letter-spacing: 1px;
}

.widget-text {
  font-size: 12px;
  color: var(--lcd-2);
  margin-top: 4px;
  word-break: break-word;
}

.widget-empty {
  text-align: center;
  color: var(--lcd-1);
  padding: 16px 0;
}

/* おみくじ */
.omikuji-display {
  background: var(--lcd-0);
  border: 2px dashed var(--lcd-2);
  padding: 12px;
  margin: 8px 0;
  width: 100%;
  min-height: 80px;
  text-align: center;
}

.omikuji-result {
  font-size: 28px;
  letter-spacing: 6px;
  margin: 8px 0;
}

.omikuji-result.best { color: var(--lcd-3); }
.omikuji-result.good { color: var(--lcd-3); }
.omikuji-result.mid { color: var(--lcd-2); }
.omikuji-result.bad { color: var(--warn); opacity: 0.8; }
.omikuji-result.worst { color: var(--warn); }

.omikuji-detail {
  text-align: left;
  font-size: 11px;
  color: var(--lcd-2);
  margin-top: 8px;
}

.omikuji-detail-row {
  display: flex;
  gap: 4px;
  border-bottom: 1px dotted var(--lcd-1);
  padding: 2px 0;
}

.omikuji-cat {
  color: var(--lcd-3);
  flex-shrink: 0;
  width: 40px;
}

/* 写真撮影画面 */
.photo-stage {
  width: 100%;
  max-width: 240px;
  aspect-ratio: 3 / 4;
  border: 2px solid var(--lcd-1);
  background: #000;
  overflow: hidden;
  position: relative;
  margin: 8px 0;
}

.photo-stage video,
.photo-stage canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}

/* 落書き Canvas */
.draw-canvas {
  border: 2px solid var(--lcd-1);
  background: var(--lcd-0);
  margin: 8px auto;
  display: block;
  touch-action: none;
  image-rendering: pixelated;
  cursor: crosshair;
}

.draw-tools {
  display: flex;
  gap: 2px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 4px 0;
}

.draw-color-btn,
.draw-tool-btn {
  font-size: 10px;
  padding: 4px 6px;
  min-width: 32px;
}

.draw-color-btn[data-draw-color="lcd-3"] { color: var(--lcd-3); }
.draw-color-btn[data-draw-color="lcd-2"] { color: var(--lcd-2); }
.draw-color-btn[data-draw-color="lcd-1"] { color: var(--lcd-1); }

/* ========================================
   v2: ゲーム共通スタイル
   ======================================== */

.game-board {
  background: var(--lcd-0);
  border: 2px solid var(--lcd-1);
  padding: 8px;
  min-height: 120px;
  font-size: 12px;
  color: var(--lcd-2);
  margin-bottom: 4px;
}

.game-actions {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.game-section {
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--lcd-1);
}

.game-section:last-child {
  border-bottom: none;
}

.game-label {
  font-size: 11px;
  color: var(--lcd-3);
  margin-bottom: 2px;
}

.game-msg {
  font-size: 12px;
  color: var(--lcd-2);
  margin: 4px 0;
}

.game-result-row {
  font-size: 12px;
  padding: 2px 0;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dotted var(--lcd-1);
}

.game-rank-tag {
  color: var(--lcd-3);
}

/* カード */
.hand-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin: 4px 0;
}

.card {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 42px;
  background: #f4f0d8;
  color: #222;
  border: 1px solid #000;
  border-radius: 2px;
  font-size: 11px;
  cursor: pointer;
  padding: 1px;
  user-select: none;
  -webkit-user-select: none;
  flex-shrink: 0;
}

.card-small {
  width: 24px;
  height: 34px;
  font-size: 9px;
}

.card-red {
  color: #c92020;
}

.card-black {
  color: #1a1a1a;
}

.card-joker {
  background: #d8d0a0;
  color: #804020;
  font-weight: bold;
}

.card-back {
  background: var(--lcd-1);
  color: var(--lcd-3);
}

.card-selected {
  background: var(--lcd-3);
  color: var(--lcd-0);
  transform: translateY(-3px);
}

.card-rank {
  font-size: 10px;
  font-weight: bold;
  line-height: 1;
}

.card-suit {
  font-size: 11px;
  line-height: 1;
  margin-top: 1px;
}

.card-selected .card-rank,
.card-selected .card-suit {
  color: var(--lcd-0);
}
