/* =====================
   ▼ CSS全体
   テーブル列構成:
   0: 名前
   1: 肉体
   2: 種族
   3: 性別(肉体性別)
   4: 年齢(肉体年齢)
   5: 体力
   6: メンタル
   7: 幸福
   8: 行動
   9: 筋力
   10: 耐久
   11: 器用
   12:魔力
   13:魅力
   14:肉体特性
   15:知力
   16:勤勉
   17:倫理
   18:勇気
   19:好色
   20:精神特性
   21:趣味
   22:(詳細: 人間関係+精神年齢+精神性別)
===================== */

body {
  margin: 0;
  padding: 0;
  font-family: sans-serif;
  background: #f5f5f5;
  color: #333;
}
header, footer {
  background: #333;
  color: #fff;
  padding: 3px;
}
main {
  padding: 3px;
}
h1, h2, h3 {
  margin-top: 0.1em;
  margin-bottom: 0.1em;
}
section {
  margin-bottom: 10px;
}
.resource-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  background: #e8e8e8;
  padding: 5px;
}
.resource-box {
  background: #fff;
  border: 1px solid #ccc;
  padding: 5px 8px;
  min-width: 80px;
  text-align: center;
}
.resource-box.resource-near-limit {
  background: #fff7e6;
  border-color: #d18a00;
}
.resource-box.resource-at-limit {
  background: #ffecec;
  border-color: #a40000;
  color: #7c0000;
}
.village-scale-title {
  min-width: 128px;
  background: #f8f0d8;
  border-color: #b8a36d;
  color: #4d3d18;
}
.resource-label,
.resource-value {
  display: block;
}
.resource-value {
  margin-top: 2px;
  font-weight: bold;
}
button {
  margin-top: 0.30em;
  margin-right: 6px;
  cursor: pointer;
}
.view-mode-toggle {
  display: inline-flex;
  vertical-align: middle;
  margin: 0 8px 4px 0;
  border: 1px solid #888;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.view-mode-button {
  min-width: 62px;
  margin: 0;
  padding: 5px 10px;
  border: 0;
  border-right: 1px solid #bbb;
  border-radius: 0;
  background: #f7f7f7;
}
.view-mode-button:last-child {
  border-right: 0;
}
.view-mode-button.is-active {
  background: #333;
  color: #fff;
  font-weight: bold;
}
.utility-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.utility-actions select {
  min-width: 150px;
}
.utility-actions select,
.utility-actions button,
.special-action-buttons button,
.action-buttons > button {
  box-sizing: border-box;
  height: 28px;
  margin: 0;
  padding: 3px 8px;
  line-height: 1.2;
}
.special-action-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
}
.mobile-spirit-toggle {
  display: none;
}
.mobile-history-spirit-actions {
  display: none;
}
.action-cell-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 226px;
  max-width: 226px;
  min-width: 0;
  margin-left: auto;
  margin-right: 2px;
}
.action-cell-controls select {
  min-width: 0;
  flex: 1 1 0;
}
#villagersTable td.action-cell,
#visitorsTable td.action-cell,
#raidEnemiesTable td.action-cell {
  width: 230px;
  max-width: 230px;
  padding-left: 3px;
  padding-right: 1px;
  text-align: center;
  white-space: nowrap;
}
.assignment-lock-toggle {
  flex: 0 0 auto;
  width: 28px;
  height: 26px;
  margin: 0;
  padding: 0;
  border: 1px solid #b8a36d;
  border-radius: 4px;
  background: #fffaf0;
  color: #5c4a19;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.assignment-lock-toggle.is-locked {
  background: #5b5143;
  border-color: #5b5143;
  color: #fff;
}
.assignment-lock-icon {
  position: relative;
  width: 13px;
  height: 10px;
  border: 2px solid currentColor;
  border-radius: 2px;
  box-sizing: border-box;
}
.assignment-lock-icon::before {
  content: "";
  position: absolute;
  left: 2px;
  top: -11px;
  width: 9px;
  height: 10px;
  border: 2px solid currentColor;
  border-bottom: 0;
  border-radius: 7px 7px 0 0;
  box-sizing: border-box;
}
.assignment-lock-icon::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 3px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
}
.assignment-lock-toggle.is-auto .assignment-lock-icon::before {
  left: 5px;
  top: -10px;
  transform: rotate(28deg);
  transform-origin: left bottom;
}
.assignment-lock-toggle.is-auto:hover {
  background: #f4ead0;
}
.assignment-lock-toggle.is-locked:hover {
  background: #706454;
}
.top-actions {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.action-buttons {
  flex: 1 1 auto;
}
.message-window {
  flex: 1 1 520px;
  min-height: 0;
  max-height: 96px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #b8a36d;
  padding: 4px 8px;
  font-size: 0.85rem;
  line-height: 1.35;
}
.message-item {
  border-top: 1px dotted #d8c7a8;
  padding: 3px 0;
}
.message-item:first-of-type {
  border-top: 0;
}
.message-item.warning {
  color: #8a4b00;
}
.message-item.danger {
  color: #a40000;
  font-weight: bold;
}
.message-empty {
  color: #666;
}
@media (max-width: 760px) {
  .top-actions {
    flex-direction: column;
  }
  .message-window {
    flex-basis: auto;
    width: calc(100% - 18px);
  }
}
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
  font-size: 0.9rem;
}
#villagersTable,
#visitorsTable,
#raidEnemiesTable {
  width: max-content;
  min-width: 100%;
}
#villagersTable th,
#villagersTable td,
#visitorsTable th,
#visitorsTable td,
#raidEnemiesTable th,
#raidEnemiesTable td {
  white-space: nowrap;
}
th, td {
  border: 1px solid #ccc;
  padding: 4px;
  text-align: center;
}
.log-and-dictionary {
  display: flex;
  gap: 20px;
  margin: 0 auto;
}
.log-area {
  height: 400px;
  overflow-y: auto;
  --village-scale-image: url("../images/village-scale-01-unnamed-hamlet.jpg");
  background:
    linear-gradient(rgba(255,255,255,0.86), rgba(255,255,255,0.91)),
    var(--village-scale-image) center / cover no-repeat #fff;
  border: 1px solid #ccc;
  padding: 5px;
  font-size: 0.85rem;
  line-height: 1.4em;
  width: 80%;
}
.dictionary-section {
  width: 20%;
}
.dictionary-search {
  margin-bottom: 10px;
}
.dictionary-search input {
  width: 100%;
  padding: 5px;
  font-size: 0.9rem;
}
.dictionary-content {
  height: 360px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #ccc;
  padding: 10px;
  font-size: 0.85rem;
  line-height: 1.4em;
}

/* モーダル(奇跡) */
#miracleModal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 2px solid #aaa;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.3);
  width: 800px;
  max-width: 90%;
  max-height: 90vh;
  box-sizing: border-box;
  padding: 20px;
  display: none;
  z-index: 999;
  overflow-y: auto;
}
#modalOverlay {
  position: fixed;
  top:0; left:0;
  width:100%; height:100%;
  background: rgba(0,0,0,0.5);
  display: none;
  z-index:998;
}
.modal-header {
  font-weight: bold;
  margin-bottom: 5px;
}
.modal-content {
  margin-top: 5px;
}
.modal-buttons {
  margin-top: 10px;
  text-align: right;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
#miracleModal .modal-buttons button:first-child {
  display: none;
}
select {
  margin: 2px 0;
}

#villageScaleOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  display: none;
  z-index: 998;
}
#villageScaleModal {
  --village-scale-image: url("../images/village-scale-01-unnamed-hamlet.jpg");
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 32px));
  min-height: 300px;
  max-height: 88vh;
  overflow-y: auto;
  display: none;
  z-index: 999;
  border: 2px solid #8d7542;
  box-shadow: 0 18px 48px rgba(0,0,0,0.32);
  background:
    linear-gradient(rgba(255,248,226,0.72), rgba(255,255,255,0.92)),
    var(--village-scale-image) center / cover no-repeat #f7efd9;
}
body.scale-stage-0 .log-area,
#villageScaleModal.scale-stage-0 {
  --village-scale-image: url("../images/village-scale-01-unnamed-hamlet.jpg");
}
body.scale-stage-1 .log-area,
#villageScaleModal.scale-stage-1 {
  --village-scale-image: url("../images/village-scale-02-small-frontier-village.jpg");
}
body.scale-stage-2 .log-area,
#villageScaleModal.scale-stage-2 {
  --village-scale-image: url("../images/village-scale-03-border-village.jpg");
}
body.scale-stage-3 .log-area,
#villageScaleModal.scale-stage-3 {
  --village-scale-image: url("../images/village-scale-04-traveler-stop.jpg");
}
body.scale-stage-4 .log-area,
#villageScaleModal.scale-stage-4 {
  --village-scale-image: url("../images/village-scale-05-rich-village.jpg");
}
body.scale-stage-5 .log-area,
#villageScaleModal.scale-stage-5 {
  --village-scale-image: url("../images/village-scale-06-prosperous-rural-village.jpg");
}
body.scale-stage-6 .log-area,
#villageScaleModal.scale-stage-6 {
  --village-scale-image: url("../images/village-scale-07-autonomous-settlement.jpg");
}
.village-scale-modal-body {
  padding: 34px 38px 28px;
  color: #2f2719;
}
.village-scale-kicker {
  font-size: 0.82rem;
  font-weight: bold;
  color: #715a27;
  letter-spacing: 0;
  margin-bottom: 6px;
}
#villageScaleModal h2 {
  margin: 0 0 12px;
  font-size: 1.55rem;
}
#villageScaleModal p {
  margin: 8px 0;
  line-height: 1.65;
}
.village-scale-current {
  color: #69562f;
  font-size: 0.9rem;
}
#villageScaleModal button {
  min-width: 96px;
  padding: 8px 16px;
  margin-top: 14px;
  border: 1px solid #7e6a3d;
  background: #4d3d18;
  color: #fff;
}

/* ▼男女色分け (列0~7) */
.male-basic {
  background: #d8e9f9; /* 薄青 */
}
.female-basic {
  background: #f9d8e9; /* 薄赤 */
}

/* ▼筋力～魅力(列8~13) => 薄黄色 */
.male-basic.happiness-cell {
  background: #d8e9f9;
}

.female-basic.happiness-cell {
  background: #f9d8e9;
}

tr td:nth-child(11),
tr td:nth-child(12),
tr td:nth-child(13),
tr td:nth-child(14),
tr td:nth-child(15),
tr td:nth-child(16) {
  background: #faf2d3;
}

/* ▼知力～好色(列14~19) => 薄緑 */
tr td:nth-child(17),
tr td:nth-child(18),
tr td:nth-child(19),
tr td:nth-child(20),
tr td:nth-child(21),
tr td:nth-child(22) {
  background: #e2f9d8;
}

/* HP/MP<=33 => 赤文字 */
.low-hpmp {
  color: red;
}

/* ステータス>=20 => 太字 */
.bold-value {
  font-weight: bold;
}
.status-debuff {
  color: #1565c0;
  font-weight: bold;
}

.dictionary-term {
  color: inherit;
  cursor: help;
  text-decoration: none;
}
.dictionary-term:focus {
  outline: 1px solid #999;
  outline-offset: 2px;
}

.spirit-column {
  display: none;
}
table.show-spirit-columns .spirit-column {
  display: table-cell;
}
.table-tools {
  margin: 2px 0 6px;
  font-size: 0.85rem;
}
.table-tools label {
  cursor: pointer;
  user-select: none;
}

.villager-portrait-cell {
  width: 42px;
  min-width: 42px;
  padding: 2px;
  background: #fff;
}
.villager-portrait-frame {
  width: 34px;
  height: 34px;
  overflow: hidden;
  border-radius: 4px;
  border: 1px solid #bbb;
  background: #fff;
  margin: 0 auto;
}
.villager-portrait {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 30%;
  display: block;
  transform: scale(1.34);
  transform-origin: center 28%;
}
#villagersTable td:nth-child(11),
#villagersTable td:nth-child(12),
#visitorsTable td:nth-child(11),
#visitorsTable td:nth-child(12),
#raidEnemiesTable td:nth-child(11),
#raidEnemiesTable td:nth-child(12) {
  background: inherit;
}
#villagersTable td:nth-child(13),
#villagersTable td:nth-child(14),
#villagersTable td:nth-child(15),
#villagersTable td:nth-child(16),
#villagersTable td:nth-child(17),
#villagersTable td:nth-child(18),
#visitorsTable td:nth-child(13),
#visitorsTable td:nth-child(14),
#visitorsTable td:nth-child(15),
#visitorsTable td:nth-child(16),
#visitorsTable td:nth-child(17),
#visitorsTable td:nth-child(18),
#raidEnemiesTable td:nth-child(13),
#raidEnemiesTable td:nth-child(14),
#raidEnemiesTable td:nth-child(15),
#raidEnemiesTable td:nth-child(16),
#raidEnemiesTable td:nth-child(17),
#raidEnemiesTable td:nth-child(18) {
  background: #faf2d3;
}
#villagersTable td:nth-child(19),
#villagersTable td:nth-child(20),
#villagersTable td:nth-child(21),
#villagersTable td:nth-child(22),
#villagersTable td:nth-child(23),
#villagersTable td:nth-child(24),
#visitorsTable td:nth-child(19),
#visitorsTable td:nth-child(20),
#visitorsTable td:nth-child(21),
#visitorsTable td:nth-child(22),
#visitorsTable td:nth-child(23),
#visitorsTable td:nth-child(24),
#raidEnemiesTable td:nth-child(19),
#raidEnemiesTable td:nth-child(20),
#raidEnemiesTable td:nth-child(21),
#raidEnemiesTable td:nth-child(22),
#raidEnemiesTable td:nth-child(23),
#raidEnemiesTable td:nth-child(24) {
  background: #e2f9d8;
}

/* 折りたたみ */
#villagersTable td.happiness-cell.male-basic,
#visitorsTable td.happiness-cell.male-basic,
#raidEnemiesTable td.happiness-cell.male-basic {
  background: #d8e9f9;
}

#villagersTable td.happiness-cell.female-basic,
#visitorsTable td.happiness-cell.female-basic,
#raidEnemiesTable td.happiness-cell.female-basic {
  background: #f9d8e9;
}

.foldable-info {
  text-align: center;
}

.person-history-button {
  min-width: 0;
  padding: 2px 4px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: #6d5b34;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
}
.person-history-button:hover,
.person-history-button:focus {
  background: #f4ead0;
  color: #3d2b13;
}

/* ---------------------
   ▼ 迎撃モーダル (襲撃イベント)
---------------------- */
#raidModal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 2px solid #aaa;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.3);
  width: min(1000px, calc(100vw - 32px));
  max-width: 1000px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  box-sizing: border-box;
  padding: 10px;
  display: none;
  z-index: 2000;
}
#raidOverlay {
  position: fixed;
  top:0; left:0;
  width:100%; height:100%;
  background: rgba(0,0,0,0.5);
  display: none;
  z-index:1999;
}
#raidModal .raid-section {
  margin-bottom: 10px;
  overflow-x: auto;
}
#raidModal h3 {
  margin: 0.5em 0;
}
#raidModal table {
  margin-bottom: 0;
}
#raidModal th,
#raidModal td {
  white-space: nowrap;
}
#raidLogArea {
  height: min(250px, 28vh);
  min-height: 140px;
  overflow-y: auto;
  background: #fdfdfd;
  border: 1px solid #ccc;
  padding: 5px;
  font-size: 0.85rem;
  line-height: 1.4em;
}
.raid-buttons {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  text-align: left;
  margin: 0 -10px 10px -10px;
  padding: 8px 10px;
  border-bottom: 1px solid #ddd;
}

/* 追加: ヘッダー内の h1 のフォントサイズを指定 */
header h1 {
  font-size: 1.0rem; /* お好みのサイズに調整してください */
}

/* 追加: 村情報のセクション内の h2 のフォントサイズを指定 */
section h2 {
  font-size: 1.0rem; /* お好みのサイズに調整してください */
}

/* 保存/ロードボタン群を右寄せする */
.save-load-buttons {
  text-align: right;
  margin-top: 5px; /* ボタン群の上に少し余白を追加 (任意) */
}

/* モーダル: 建築・秘宝・村史・個人記録 */
#buildingOverlay,
#secretTreasureOverlay,
#historyOverlay,
#personalHistoryOverlay {
  position: fixed;
  top:0; left:0;
  width:100%; height:100%;
  background: rgba(0,0,0,0.5);
  display: none;
  z-index:998;
}
#buildingModal,
#secretTreasureModal,
#historyModal,
#personalHistoryModal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 2px solid #aaa;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.3);
  width: 800px;
  max-width: 90%;
  max-height: 90vh;
  padding: 20px;
  display: none;
  z-index: 999;
  overflow-y: auto;
}
#buildingContent,
#secretTreasureContent,
#historyContent,
#personalHistoryContent {
  margin-top: 5px;
}
#historyModal,
#personalHistoryModal {
  background: #f7f0e3;
  border: 1px solid #9b875d;
  box-shadow: 0 18px 48px rgba(28, 20, 10, 0.38);
  color: #2f2618;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", "Times New Roman", serif;
}
#historyModal .modal-header,
#personalHistoryModal .modal-header {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 3px double #bba575;
  color: #2f2618;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  font-size: 1.22rem;
  font-weight: bold;
}
#historyContent,
#personalHistoryContent {
  padding: 18px 22px;
  background:
    linear-gradient(90deg, rgba(122, 94, 45, 0.06) 0, rgba(122, 94, 45, 0) 18px),
    #fbf6ea;
  border: 1px solid #e0d1ad;
}
.personal-history-summary {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  margin: 0 0 16px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  color: #2f2618;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
}
.personal-history-portrait-frame {
  width: 96px;
  aspect-ratio: 1;
  background: #e8dfcb;
  border: 1px solid #bda978;
  overflow: hidden;
}
.personal-history-portrait-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.personal-history-profile {
  min-width: 0;
}
.personal-history-profile-name {
  margin-bottom: 8px;
  font-weight: bold;
  font-size: 1.05rem;
}
.personal-history-profile-grid {
  display: grid;
  gap: 0;
  overflow-x: auto;
}
.personal-history-profile-table {
  display: grid;
  grid-template-columns: 6em max-content max-content max-content max-content;
  justify-content: start;
  gap: 3px 10px;
  align-items: baseline;
  width: max-content;
  padding-bottom: 7px;
  border-bottom: 1px solid #d9ccb0;
}
.personal-history-profile-label {
  color: #6d5b34;
  font-size: 0.76rem;
  line-height: 1.25;
  white-space: nowrap;
}
.personal-history-profile-value {
  min-width: 0;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: nowrap;
}
.personal-history-profile-label.is-body,
.personal-history-profile-label.is-spirit,
.personal-history-profile-label.is-hobby,
.personal-history-profile-value.is-body,
.personal-history-profile-value.is-spirit,
.personal-history-profile-value.is-hobby {
  margin-left: 10px;
}
.personal-history-profile-field {
  min-width: 0;
}
.personal-history-profile-field.is-detail {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 6em minmax(0, 1fr);
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid #d9ccb0;
}
.personal-history-profile-field span {
  display: block;
  color: #6d5b34;
  font-size: 0.76rem;
  line-height: 1.25;
}
.personal-history-profile-field strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
  line-height: 1.45;
}
.personal-history-profile-field.is-detail span,
.personal-history-profile-field.is-detail strong {
  line-height: 1.55;
}
.personal-history-note {
  margin: 0 0 14px;
  padding: 8px 0;
  border-top: 1px solid #e3d7bd;
  border-bottom: 1px solid #e3d7bd;
  color: #73654b;
  font-size: 0.92rem;
}
.history-list {
  display: grid;
  gap: 0;
}
.history-entry {
  background: transparent;
  border-bottom: 1px solid #e5d8b8;
  padding: 11px 0 12px;
}
.history-entry:first-child {
  padding-top: 0;
}
.history-entry:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}
.history-record-line {
  display: grid;
  grid-template-columns: 7.5em minmax(0, 1fr);
  gap: 12px;
  align-items: baseline;
  margin: 0;
  line-height: 1.8;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", "Times New Roman", serif;
  font-size: 1.02rem;
}
.history-date {
  color: #7a633b;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  white-space: nowrap;
}
.history-record-text {
  color: #2f2618;
  overflow-wrap: anywhere;
}
.history-empty {
  color: #73654b;
  padding: 12px 0;
  line-height: 1.8;
}
.secret-treasure-select-label,
.secret-treasure-target-label {
  display: grid;
  gap: 6px;
}
.secret-treasure-select-label select,
.secret-treasure-target-label select {
  width: 100%;
  max-width: 360px;
}
.secret-treasure-target-label {
  margin-top: 10px;
}
.secret-treasure-description {
  margin-top: 12px;
  padding: 10px;
  background: #f5f5f5;
  border-radius: 4px;
  color: #555;
}

.event-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 2600;
}

.event-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(680px, calc(100vw - 32px));
  max-height: min(86vh, 760px);
  overflow: auto;
  background: #fff;
  color: #222;
  border: 1px solid #7a5c32;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
  z-index: 2601;
}

.event-modal-image {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #221b14;
}

.event-modal-body {
  padding: 16px;
}

.event-modal-body h3 {
  margin: 0 0 10px;
  color: #5d3d12;
}

.event-modal-body p {
  margin: 0 0 10px;
  line-height: 1.6;
}

.event-modal-reward {
  font-weight: bold;
}

.event-modal-buttons {
  margin-top: 14px;
  text-align: right;
}
.building-item {
  border: 1px solid #ddd;
  padding: 15px;
  background: #f9f9f9;
  border-radius: 4px;
  transition: all 0.2s;
}
.building-item:hover {
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.building-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.building-header h4 {
  margin: 0;
  color: #333;
  min-width: 0;
}
.built-mark {
  background: #4CAF50;
  color: white;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.8em;
}
.building-desc {
  color: #666;
  margin-bottom: 10px;
  min-height: 2.4em;
}
.building-cost {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.9em;
  color: #555;
  margin-bottom: 10px;
}
.building-reason {
  color: #f44336;
  font-size: 0.9em;
  margin-bottom: 10px;
}
.building-button {
  width: 100%;
  padding: 8px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}
.building-button:not(:disabled) {
  background: #2196F3;
  color: white;
}
.building-button:not(:disabled):hover {
  background: #1976D2;
}
.building-button:disabled {
  background: #ddd;
  cursor: not-allowed;
}
.building-button.built {
  background: #4CAF50;
  color: white;
}
.built-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}
.built-item {
  background: #4CAF50;
  color: white;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.9em;
}
.building-resources {
  display: flex;
  gap: 20px;
  background: #f5f5f5;
  padding: 10px;
  margin-bottom: 15px;
  border-radius: 4px;
  font-weight: bold;
}
.building-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 15px;
  margin-top: 10px;
}
.built-count {
  background: #2196F3;
  color: white;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.8em;
  margin-left: 8px;
}

.miracle-resources {
  display: flex;
  gap: 20px;
  background: #f5f5f5;
  padding: 10px;
  margin-bottom: 15px;
  border-radius: 4px;
  font-weight: bold;
}

.miracle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 15px;
  margin-top: 10px;
}

.miracle-item {
  border: 1px solid #ddd;
  padding: 15px;
  background: #f9f9f9;
  border-radius: 4px;
  transition: all 0.2s;
  cursor: pointer;
}

.miracle-item:hover,
.miracle-item.active {
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.miracle-item.active {
  border-color: #2196F3;
  background: #f7fbff;
}

.miracle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.miracle-header h4 {
  margin: 0;
  color: #333;
}

.miracle-mark {
  background: #2196F3;
  color: white;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.8em;
  white-space: nowrap;
}

.miracle-desc {
  color: #666;
  margin-bottom: 10px;
  min-height: 2.4em;
}

.miracle-cost {
  display: flex;
  gap: 10px;
  font-size: 0.9em;
  color: #555;
  margin-bottom: 10px;
}

.miracle-reason {
  color: #f44336;
  font-size: 0.9em;
  margin-bottom: 10px;
}

.miracle-targets {
  display: grid;
  gap: 8px;
  margin: 10px 0;
  padding: 10px;
  background: #fff;
  border: 1px solid #e4e4e4;
  border-radius: 4px;
}

.miracle-target {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 8px;
  align-items: center;
  font-size: 0.9em;
}

.miracle-target select {
  width: 100%;
  min-width: 0;
}

.miracle-preview {
  color: #444;
  font-size: 0.86em;
  line-height: 1.45;
  padding-top: 4px;
  border-top: 1px solid #eee;
}

.miracle-button {
  width: 100%;
  padding: 8px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.miracle-button:not(:disabled) {
  background: #673AB7;
  color: white;
}

.miracle-button:not(:disabled):hover {
  background: #512DA8;
}

.miracle-button:disabled {
  background: #ddd;
  cursor: not-allowed;
}

/* 月末サマリーモーダル用スタイル */
#monthEndModal {
  font-size: 0.9rem;
  width: 600px;
}

#monthEndModal h3 {
  color: #333;
  border-bottom: 1px solid #ddd;
  padding-bottom: 10px;
}

#monthEndModal button {
  background: #4CAF50;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}

#monthEndModal button:hover {
  background: #45a049;
}

/* 月末サマリーモーダル用スタイルに追加 */
.tab-container {
  margin-top: 15px;
}

.tab-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}

.tab-button {
  padding: 8px 16px;
  border: none;
  background: #f0f0f0;
  cursor: pointer;
  border-radius: 4px;
}

.tab-button.active {
  background: #4CAF50;
  color: white;
}

.tab-content {
  display: none;
  max-height: 50vh;
  overflow-y: auto;
  padding: 10px;
  background: #f9f9f9;
  border-radius: 4px;
}

.tab-content.active {
  display: block;
}

.tab-content h4 {
  margin-top: 0;
  color: #333;
}

/* 会話モーダル用のスタイル */
#conversationOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  display: none;
  z-index: 2001;
}

#conversationModal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 2px solid #aaa;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.3);
  width: 600px;
  max-width: 90%;
  padding: 20px;
  display: none;
  z-index: 2002;
}

.conversation-content {
  display: flex;
  gap: 20px;
}

.portrait-area {
  width: 200px;
  height: 200px;
  background: #f0f0f0;
}

.portrait-area img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dialogue-area {
  flex: 1;
  min-height: 200px;
  padding: 10px;
  background: #f9f9f9;
  border-radius: 4px;
}

/* 行動ボタン用のスタイル */
#actionButtons {
  margin-top: 15px;
  display: flex;
  gap: 10px;
}

#actionButtons button {
  padding: 8px 12px;
  border: 1px solid #ccc;
  background-color: #f0f0f0;
  cursor: pointer;
  transition: all 0.2s;
}

#actionButtons button:hover {
  background-color: #e0e0e0;
}

#actionButtons button.active-action {
  background-color: #4CAF50;
  color: white;
  border-color: #45a049;
}

#actionButtons button.active-action:hover {
  background-color: #45a049;
}

#raidWarningOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2100;
}

#raidWarningModal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 2px solid #aaa;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.3);
  width: 600px;
  max-width: 90%;
  max-height: 90vh;
  box-sizing: border-box;
  padding: 20px;
  overflow-y: auto;
  z-index: 2101;
}

#raidWarningModal h2 {
  margin: 0 0 12px;
  color: #9d2b22;
  font-size: 1.2rem;
  letter-spacing: 0;
}

#raidWarningModal .raid-warning-text p {
  margin: 0 0 12px;
  line-height: 1.6;
}

#raidWarningModal .raid-warning-detail {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid #ddd;
  color: #555;
  font-size: 0.9rem;
  line-height: 1.5;
}

#raidWarningModal .modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 15px;
}

#raidWarningModal .modal-buttons button {
  min-width: 104px;
  padding: 8px 12px;
  border: 1px solid #ccc;
  background-color: #f0f0f0;
  cursor: pointer;
}

#raidWarningModal .modal-buttons button:hover:not(:disabled) {
  background-color: #e0e0e0;
}

#raidWarningModal .modal-buttons button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

/* 交換モーダル用のスタイル */
#exchangeOverlay,
#panFluteExchangeOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  display: none;
  z-index: 2001;
}

#exchangeModal,
#panFluteExchangeModal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 2px solid #aaa;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.3);
  width: 800px;
  max-width: 90%;
  max-height: 90vh;
  box-sizing: border-box;
  padding: 20px;
  display: none;
  z-index: 2002;
  overflow-y: auto;
}

.exchange-content,
.pan-flute-exchange-content {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.exchange-title {
  text-align: center;
  margin-bottom: 20px;
}

.exchange-title h3 {
  margin: 0;
  color: #a83232;
}

.character-exchange {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.exchange-character {
  flex: 1;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8f8f8;
  padding: 15px;
  border-radius: 5px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.exchange-character .portrait-area {
  width: 150px;
  height: 150px;
  margin: 0 auto;
  background: #eee;
}

.exchange-character .portrait-area img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.exchange-character .dialogue-area {
  padding: 10px;
  background: #fff;
  border-radius: 4px;
  border: 1px solid #ddd;
  min-height: 80px;
}

.pan-flute-exchange-pairs {
  width: 100%;
  display: grid;
  gap: 10px;
}

.pan-flute-pair {
  width: 100%;
  display: grid;
  gap: 6px;
  padding: 10px;
  background: #f8f8f8;
  border: 1px solid #ddd;
  border-radius: 5px;
}

.pan-flute-pair-label {
  font-weight: bold;
  color: #6b4b1f;
}

.pan-flute-pair-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
}

.pan-flute-person {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.pan-flute-portrait {
  width: 72px;
  height: 72px;
  background: #eee;
}

.pan-flute-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pan-flute-dialogue {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 7px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.9rem;
}

.pan-flute-dialogue span {
  overflow-wrap: anywhere;
}

.pan-flute-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  color: #a83232;
  font-weight: bold;
}

/* キャラクター情報のスタイルを調整 */
.character-info {
  margin-bottom: 12px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 8px;
}

.character-name {
  font-size: 1em;
}

.character-details {
  display: flex;
  justify-content: flex-start;
  gap: 12px;
  font-size: 0.9em;
  color: #555;
}

.character-details span {
  white-space: nowrap;
}

/* ---------------------
   スマホ横向きモード
---------------------- */
body.mobile-mode {
  font-size: 14px;
  line-height: 1.25;
  background: #f2f4f1;
}
body.mobile-mode header {
  display: none;
}
body.mobile-mode header,
body.mobile-mode footer {
  padding: 4px 6px;
}
body.mobile-mode h1 {
  font-size: 0.92rem;
  line-height: 1.15;
}
body.mobile-mode h2 {
  font-size: 0.82rem;
  line-height: 1.1;
  margin-bottom: 3px;
}
body.mobile-mode main {
  padding: 3px 5px;
}
body.mobile-mode section {
  margin-bottom: 5px;
  overflow-x: auto;
}
body.mobile-mode main > section:first-child {
  display: flex;
  flex-direction: column;
  overflow-x: visible;
}
body.mobile-mode main > section:first-child > h2 {
  display: none;
}
body.mobile-mode main > section:nth-of-type(2) > h2 {
  display: none;
}
body.mobile-mode main > section:nth-of-type(2) {
  display: flex;
  flex-direction: column;
  margin-bottom: 1px;
}
body.mobile-mode .resource-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 18px;
  width: 100%;
  padding: 4px 8px;
  border: 1px solid #c9d3c8;
  background: #fff;
  box-sizing: border-box;
}
body.mobile-mode .resource-box {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.38em;
  flex: 0 0 auto;
  min-width: auto;
  min-height: 0;
  padding: 1px 0;
  border: 0;
  background: transparent;
  font-size: 0.69rem;
  line-height: 1.05;
  text-align: left;
}
body.mobile-mode .resource-label {
  flex: 0 0 auto;
  color: #555;
  font-size: 0.74rem;
  white-space: nowrap;
}
body.mobile-mode .resource-value {
  min-width: auto;
  margin-top: 0;
  overflow: visible;
  font-size: 0.88rem;
  font-weight: 700;
  text-align: left;
  text-overflow: clip;
  white-space: nowrap;
}
body.mobile-mode .resource-box.resource-near-limit .resource-value {
  color: #8a4b00;
}
body.mobile-mode .resource-box.resource-at-limit .resource-value {
  color: #a40000;
}
body.mobile-mode .village-scale-title {
  min-width: 8.5em;
}
body.mobile-mode .resource-traits {
  min-width: auto;
}
body.mobile-mode .top-actions {
  display: contents;
}
body.mobile-mode .action-buttons {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
  order: 1;
  width: 100%;
}
body.mobile-mode .resource-panel {
  order: 2;
  margin-top: 4px;
}
body.mobile-mode .view-mode-toggle {
  order: 1;
  grid-row: 1;
  grid-column: 5 / span 2;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
}
body.mobile-mode .view-mode-button,
body.mobile-mode .action-buttons > button,
body.mobile-mode .special-action-buttons button {
  width: 100%;
  min-height: 36px;
  margin: 0;
  padding: 6px 4px;
  font-size: 0.75rem;
  line-height: 1.15;
}
body.mobile-mode #nextTurnButton {
  order: 2;
  grid-row: 2;
  grid-column: 3 / span 2;
  min-height: 42px;
  font-size: 0.96rem;
  font-weight: bold;
}
body.mobile-mode #autoAssignButton {
  order: 2;
  grid-row: 2;
  grid-column: 1 / span 2;
}
body.mobile-mode .action-buttons.is-raid-mode #autoAssignButton,
body.mobile-mode .action-buttons.is-raid-mode #raidAssignButton {
  grid-column: span 1;
}
body.mobile-mode .special-action-buttons {
  order: 2;
  grid-row: 2;
  grid-column: 5 / span 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}
body.mobile-mode .pc-history-button {
  display: none;
}
body.mobile-mode .utility-actions {
  display: grid;
  order: 1;
  grid-row: 1;
  grid-column: 1 / span 3;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 4px;
}
body.mobile-mode .action-buttons > button:not(#autoAssignButton):not(#raidAssignButton):not(#nextTurnButton) {
  order: 2;
  grid-row: 2;
}
body.mobile-mode #raidAssignButton {
  order: 2;
  grid-row: 2;
}
body.mobile-mode .utility-actions select,
body.mobile-mode .utility-actions button {
  width: 100%;
  min-height: 36px;
  margin: 0;
  padding: 6px 4px;
  font-size: 0.75rem;
  line-height: 1.15;
}
body.mobile-mode .mobile-history-spirit-actions {
  order: 1;
  grid-row: 1;
  grid-column: 4 / span 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px;
}
body.mobile-mode .mobile-spirit-toggle,
body.mobile-mode .mobile-history-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 2px;
  border: 1px solid #777;
  border-radius: 4px;
  background: #eee;
  box-sizing: border-box;
  font-size: 0.72rem;
  line-height: 1.1;
  cursor: pointer;
  user-select: none;
}
body.mobile-mode .mobile-history-button {
  margin: 0;
  color: #111;
}
body.mobile-mode .mobile-spirit-toggle input {
  width: 14px;
  height: 14px;
  min-height: 0;
  margin: 0 2px 0 0;
}
body.mobile-mode .message-window {
  flex: 0 0 auto;
  order: 3;
  width: auto;
  margin-top: 4px;
  max-height: 40px;
  padding: 3px 6px;
  font-size: 0.72rem;
  line-height: 1.2;
}
body.mobile-mode .message-item {
  padding: 2px 0;
}
body.mobile-mode main > section:nth-of-type(2) > .table-tools {
  display: none;
}
body.mobile-mode #villagersTable,
body.mobile-mode #visitorsTable,
body.mobile-mode #raidEnemiesTable {
  width: 100%;
  min-width: 0;
  margin-bottom: 1px;
  table-layout: fixed;
  font-size: 0.48rem;
}
body.mobile-mode #villagersTable th,
body.mobile-mode #villagersTable td,
body.mobile-mode #visitorsTable th,
body.mobile-mode #visitorsTable td,
body.mobile-mode #raidEnemiesTable th,
body.mobile-mode #raidEnemiesTable td {
  padding: 1px 1px;
  line-height: 1.05;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
body.mobile-mode #villagersTable td:nth-child(18),
body.mobile-mode #villagersTable td:nth-child(24),
body.mobile-mode #visitorsTable td:nth-child(18),
body.mobile-mode #visitorsTable td:nth-child(24),
body.mobile-mode #raidEnemiesTable td:nth-child(18),
body.mobile-mode #raidEnemiesTable td:nth-child(24) {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.15;
}
body.mobile-mode #villagersTable th,
body.mobile-mode #visitorsTable th,
body.mobile-mode #raidEnemiesTable th {
  font-size: 0.48rem;
  font-weight: bold;
}
body.mobile-mode #villagersTable th:nth-child(1),
body.mobile-mode #villagersTable td:nth-child(1),
body.mobile-mode #visitorsTable th:nth-child(1),
body.mobile-mode #visitorsTable td:nth-child(1),
body.mobile-mode #raidEnemiesTable th:nth-child(1),
body.mobile-mode #raidEnemiesTable td:nth-child(1) {
  width: 2.2%;
}
body.mobile-mode #villagersTable th:nth-child(2),
body.mobile-mode #villagersTable td:nth-child(2),
body.mobile-mode #visitorsTable th:nth-child(2),
body.mobile-mode #visitorsTable td:nth-child(2),
body.mobile-mode #raidEnemiesTable th:nth-child(2),
body.mobile-mode #raidEnemiesTable td:nth-child(2) {
  width: 4.7%;
}
body.mobile-mode #villagersTable th:nth-child(3),
body.mobile-mode #villagersTable td:nth-child(3),
body.mobile-mode #visitorsTable th:nth-child(3),
body.mobile-mode #visitorsTable td:nth-child(3),
body.mobile-mode #raidEnemiesTable th:nth-child(3),
body.mobile-mode #raidEnemiesTable td:nth-child(3) {
  width: 4.7%;
}
body.mobile-mode #villagersTable th:nth-child(4),
body.mobile-mode #villagersTable td:nth-child(4),
body.mobile-mode #villagersTable th:nth-child(5),
body.mobile-mode #villagersTable td:nth-child(5),
body.mobile-mode #villagersTable th:nth-child(6),
body.mobile-mode #villagersTable td:nth-child(6),
body.mobile-mode #visitorsTable th:nth-child(4),
body.mobile-mode #visitorsTable td:nth-child(4),
body.mobile-mode #visitorsTable th:nth-child(5),
body.mobile-mode #visitorsTable td:nth-child(5),
body.mobile-mode #visitorsTable th:nth-child(6),
body.mobile-mode #visitorsTable td:nth-child(6),
body.mobile-mode #raidEnemiesTable th:nth-child(4),
body.mobile-mode #raidEnemiesTable td:nth-child(4),
body.mobile-mode #raidEnemiesTable th:nth-child(5),
body.mobile-mode #raidEnemiesTable td:nth-child(5),
body.mobile-mode #raidEnemiesTable th:nth-child(6),
body.mobile-mode #raidEnemiesTable td:nth-child(6) {
  width: 2.4%;
}
body.mobile-mode #villagersTable th:nth-child(7),
body.mobile-mode #villagersTable td:nth-child(7),
body.mobile-mode #villagersTable th:nth-child(8),
body.mobile-mode #villagersTable td:nth-child(8),
body.mobile-mode #visitorsTable th:nth-child(7),
body.mobile-mode #visitorsTable td:nth-child(7),
body.mobile-mode #visitorsTable th:nth-child(8),
body.mobile-mode #visitorsTable td:nth-child(8),
body.mobile-mode #raidEnemiesTable th:nth-child(7),
body.mobile-mode #raidEnemiesTable td:nth-child(7),
body.mobile-mode #raidEnemiesTable th:nth-child(8),
body.mobile-mode #raidEnemiesTable td:nth-child(8) {
  width: 3%;
}
body.mobile-mode #villagersTable th:nth-child(9),
body.mobile-mode #villagersTable td:nth-child(9),
body.mobile-mode #villagersTable th:nth-child(10),
body.mobile-mode #villagersTable td:nth-child(10),
body.mobile-mode #villagersTable th:nth-child(11),
body.mobile-mode #villagersTable td:nth-child(11),
body.mobile-mode #visitorsTable th:nth-child(9),
body.mobile-mode #visitorsTable td:nth-child(9),
body.mobile-mode #visitorsTable th:nth-child(10),
body.mobile-mode #visitorsTable td:nth-child(10),
body.mobile-mode #visitorsTable th:nth-child(11),
body.mobile-mode #visitorsTable td:nth-child(11),
body.mobile-mode #raidEnemiesTable th:nth-child(9),
body.mobile-mode #raidEnemiesTable td:nth-child(9),
body.mobile-mode #raidEnemiesTable th:nth-child(10),
body.mobile-mode #raidEnemiesTable td:nth-child(10),
body.mobile-mode #raidEnemiesTable th:nth-child(11),
body.mobile-mode #raidEnemiesTable td:nth-child(11) {
  width: 2.7%;
}
body.mobile-mode #villagersTable th:nth-child(12),
body.mobile-mode #villagersTable td:nth-child(12),
body.mobile-mode #visitorsTable th:nth-child(12),
body.mobile-mode #visitorsTable td:nth-child(12),
body.mobile-mode #raidEnemiesTable th:nth-child(12),
body.mobile-mode #raidEnemiesTable td:nth-child(12) {
  width: 8.8%;
}
body.mobile-mode #villagersTable th:nth-child(n+13):nth-child(-n+17),
body.mobile-mode #villagersTable td:nth-child(n+13):nth-child(-n+17),
body.mobile-mode #villagersTable th:nth-child(n+19):nth-child(-n+23),
body.mobile-mode #villagersTable td:nth-child(n+19):nth-child(-n+23),
body.mobile-mode #visitorsTable th:nth-child(n+13):nth-child(-n+17),
body.mobile-mode #visitorsTable td:nth-child(n+13):nth-child(-n+17),
body.mobile-mode #visitorsTable th:nth-child(n+19):nth-child(-n+23),
body.mobile-mode #visitorsTable td:nth-child(n+19):nth-child(-n+23),
body.mobile-mode #raidEnemiesTable th:nth-child(n+13):nth-child(-n+17),
body.mobile-mode #raidEnemiesTable td:nth-child(n+13):nth-child(-n+17),
body.mobile-mode #raidEnemiesTable th:nth-child(n+19):nth-child(-n+23),
body.mobile-mode #raidEnemiesTable td:nth-child(n+19):nth-child(-n+23) {
  width: 2.2%;
}
body.mobile-mode #villagersTable th:nth-child(18),
body.mobile-mode #villagersTable td:nth-child(18),
body.mobile-mode #villagersTable th:nth-child(24),
body.mobile-mode #villagersTable td:nth-child(24),
body.mobile-mode #visitorsTable th:nth-child(18),
body.mobile-mode #visitorsTable td:nth-child(18),
body.mobile-mode #visitorsTable th:nth-child(24),
body.mobile-mode #visitorsTable td:nth-child(24),
body.mobile-mode #raidEnemiesTable th:nth-child(18),
body.mobile-mode #raidEnemiesTable td:nth-child(18),
body.mobile-mode #raidEnemiesTable th:nth-child(24),
body.mobile-mode #raidEnemiesTable td:nth-child(24) {
  width: 4.5%;
}
body.mobile-mode #villagersTable th:nth-child(26),
body.mobile-mode #villagersTable td:nth-child(26),
body.mobile-mode #visitorsTable th:nth-child(26),
body.mobile-mode #visitorsTable td:nth-child(26),
body.mobile-mode #raidEnemiesTable th:nth-child(26),
body.mobile-mode #raidEnemiesTable td:nth-child(26) {
  width: 3.6%;
}
body.mobile-mode #villagersTable th:nth-child(25),
body.mobile-mode #villagersTable td:nth-child(25),
body.mobile-mode #visitorsTable th:nth-child(25),
body.mobile-mode #visitorsTable td:nth-child(25),
body.mobile-mode #raidEnemiesTable th:nth-child(25),
body.mobile-mode #raidEnemiesTable td:nth-child(25) {
  width: 3.4%;
}
body.mobile-mode select,
body.mobile-mode input,
body.mobile-mode textarea {
  min-height: 30px;
  font-size: 0.72rem;
}
body.mobile-mode #villagersTable select,
body.mobile-mode #visitorsTable select,
body.mobile-mode #raidEnemiesTable select {
  width: 100%;
  min-height: 20px;
  font-size: 0.5rem;
}
body.mobile-mode .action-cell-controls {
  gap: 2px;
  width: 100%;
  max-width: none;
  min-width: 0;
}
body.mobile-mode .action-cell-controls select {
  min-width: 0;
}
body.mobile-mode .assignment-lock-toggle {
  width: 18px;
  height: 20px;
}
body.mobile-mode .villager-portrait-cell {
  width: 2.2%;
  min-width: 0;
}
body.mobile-mode .villager-portrait-frame {
  width: 18px;
  height: 18px;
}
body.mobile-mode .table-tools {
  margin: 1px 0 4px;
  font-size: 0.72rem;
}
body.mobile-mode .log-dictionary-section > h2 {
  display: none;
}
body.mobile-mode .log-and-dictionary {
  flex-direction: column;
  gap: 5px;
}
body.mobile-mode .log-area {
  order: 2;
  width: auto;
  height: 190px;
  font-size: 0.72rem;
}
body.mobile-mode .dictionary-section {
  order: 1;
  width: auto;
}
body.mobile-mode .dictionary-search {
  margin-bottom: 1px;
}
body.mobile-mode .dictionary-search input {
  min-height: 0;
  height: 24px;
  padding: 3px 6px;
  box-sizing: border-box;
  font-size: 0.72rem;
  line-height: 1.2;
}
body.mobile-mode .dictionary-content {
  height: 82px;
  padding: 5px 6px;
  font-size: 0.72rem;
}
body.mobile-mode .person-history-button {
  width: 100%;
  min-width: 0;
  padding: 1px;
  font-size: 0.62rem;
  line-height: 1.2;
}
body.mobile-mode .personal-history-summary {
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 8px;
  padding: 0;
}
body.mobile-mode .personal-history-portrait-frame {
  width: 64px;
}
body.mobile-mode .personal-history-profile-name {
  margin-bottom: 5px;
  font-size: 0.9rem;
}
body.mobile-mode .personal-history-profile-grid {
  gap: 5px;
}
body.mobile-mode .personal-history-profile-table {
  grid-template-columns: 3.2em max-content max-content max-content max-content;
  gap: 2px;
  padding-bottom: 5px;
}
body.mobile-mode .personal-history-profile-field.is-detail {
  grid-column: 1 / -1;
  grid-template-columns: 3.2em minmax(0, 1fr);
  gap: 6px;
  padding: 5px 0;
}
body.mobile-mode .personal-history-profile-label {
  font-size: 0.58rem;
}
body.mobile-mode .personal-history-profile-value {
  font-size: 0.6rem;
  line-height: 1.3;
}
body.mobile-mode .personal-history-profile-label.is-body,
body.mobile-mode .personal-history-profile-label.is-spirit,
body.mobile-mode .personal-history-profile-label.is-hobby,
body.mobile-mode .personal-history-profile-value.is-body,
body.mobile-mode .personal-history-profile-value.is-spirit,
body.mobile-mode .personal-history-profile-value.is-hobby {
  margin-left: 0;
}
body.mobile-mode .personal-history-profile-field span {
  font-size: 0.68rem;
}
body.mobile-mode .personal-history-profile-field strong {
  font-size: 0.75rem;
}
body.mobile-mode .history-record-line {
  grid-template-columns: 5.8em minmax(0, 1fr);
  gap: 7px;
  line-height: 1.65;
}
body.mobile-mode #miracleModal,
body.mobile-mode #buildingModal,
body.mobile-mode #secretTreasureModal,
body.mobile-mode #historyModal,
body.mobile-mode #personalHistoryModal,
body.mobile-mode #conversationModal,
body.mobile-mode #raidWarningModal,
body.mobile-mode #exchangeModal,
body.mobile-mode #panFluteExchangeModal,
body.mobile-mode #raidModal,
body.mobile-mode #villageScaleModal,
body.mobile-mode #monthEndModal,
body.mobile-mode .event-modal {
  top: 8px;
  left: 50%;
  width: min(880px, calc(100vw - 16px));
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 16px);
  padding: 8px;
  overflow-y: auto;
  box-sizing: border-box;
  transform: translateX(-50%);
}
body.mobile-mode .modal-header {
  margin-bottom: 4px;
  font-size: 0.9rem;
}
body.mobile-mode .modal-content {
  margin-top: 3px;
}
body.mobile-mode .modal-buttons {
  position: sticky;
  bottom: 0;
  margin: 8px -8px -8px;
  padding: 6px 8px;
  background: #fff;
  border-top: 1px solid #ddd;
}
body.mobile-mode #historyModal .modal-buttons,
body.mobile-mode #personalHistoryModal .modal-buttons {
  background: #f7f0e3;
  border-top: 1px solid #d2bd8b;
  box-shadow: 0 -8px 0 #f7f0e3;
}
body.mobile-mode .modal-buttons button,
body.mobile-mode #actionButtons button,
body.mobile-mode .building-button,
body.mobile-mode .miracle-button,
body.mobile-mode .tab-button {
  min-height: 38px;
  font-size: 0.82rem;
}
body.mobile-mode .conversation-content {
  gap: 10px;
}
body.mobile-mode .portrait-area {
  flex: 0 0 128px;
  width: 128px;
  height: 128px;
}
body.mobile-mode .dialogue-area {
  min-height: 128px;
  max-height: calc(100vh - 92px);
  overflow-y: auto;
}
body.mobile-mode #actionButtons {
  flex-wrap: wrap;
  gap: 6px;
}
body.mobile-mode .exchange-title {
  margin-bottom: 8px;
}
body.mobile-mode .character-exchange {
  gap: 8px;
  width: 100%;
}
body.mobile-mode .exchange-character {
  min-width: 0;
  padding: 8px;
}
body.mobile-mode .exchange-character .portrait-area {
  width: 96px;
  height: 96px;
}
body.mobile-mode .pan-flute-pair {
  padding: 8px;
}
body.mobile-mode .pan-flute-pair-body {
  grid-template-columns: 1fr;
  gap: 6px;
}
body.mobile-mode .pan-flute-person {
  grid-template-columns: 56px minmax(0, 1fr);
}
body.mobile-mode .pan-flute-portrait {
  width: 56px;
  height: 56px;
}
body.mobile-mode .pan-flute-dialogue {
  font-size: 0.78rem;
  padding: 6px;
}
body.mobile-mode .pan-flute-arrow {
  min-height: 16px;
}
body.mobile-mode .building-resources {
  gap: 8px;
  padding: 6px;
  margin-bottom: 8px;
  font-size: 0.78rem;
}
body.mobile-mode .miracle-resources {
  gap: 8px;
  padding: 6px;
  margin-bottom: 8px;
  font-size: 0.78rem;
}
body.mobile-mode .building-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr));
  gap: 8px;
}
body.mobile-mode .miracle-grid {
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
}
body.mobile-mode .building-item {
  padding: 9px;
}
body.mobile-mode .miracle-item {
  padding: 9px;
}
body.mobile-mode #raidModal {
  padding: 8px;
}
body.mobile-mode #raidModal .raid-section {
  margin-bottom: 7px;
}
body.mobile-mode #raidModal table {
  min-width: 0;
  font-size: 0.76rem;
}
body.mobile-mode .raid-buttons {
  margin: 0 -8px 8px;
  padding: 6px 8px;
}
body.mobile-mode .raid-buttons button {
  width: 100%;
  min-height: 44px;
  font-size: 0.95rem;
}
body.mobile-mode #raidLogArea {
  height: 118px;
  font-size: 0.72rem;
}

@media (max-width: 720px) {
  body.mobile-mode main > section:first-child {
    grid-template-columns: 1fr;
  }
  body.mobile-mode .action-buttons {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
  body.mobile-mode .resource-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
