/* Reset & Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Prevent text dragging in inputs and textareas */
input,
textarea,
select {
  -webkit-user-drag: none;
  user-select: text;
}
input[type="text"],
textarea {
  -webkit-user-select: text;
  user-select: text;
}
input:not([type="text"]),
select {
  -webkit-user-select: none;
  user-select: none;
}

@font-face {
  font-family: 'DF-FutoMaruGothic';
  src: url('/fonts/DF-FutoMaruGothic-W9-CAB-18277f51d7ae7c3bd42f53247de2bb48--4329643920678357007.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'HeiSeiMaruGothic';
  src: url('/fonts/DF-HeiSeiMaruGothic-W4-CAB-18277f51d7ae7c3bd42f53247de2bb48-2057771419379400601.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --primary: #E8792B;
  --primary-dark: #D06820;
  --primary-light: #F5B88C;
  --secondary: #FFB830;
  --accent-pink: #F4A0B0;
  --accent-green: #B8D430;
  --bg: #FFF8F0;
  --bg-light: #FFF0E6;
  --surface: #FFE4D6;
  --surface-dark: #F5D0C0;
  --card-bg: #FFFFFF;
  --text: #5C4033;
  --text-muted: #8B7355;
  --text-secondary: #8B7355;
  --success: #7CB342;
  --error: #E53935;
  --warning: #FFB830;

  /* Themeable rgba values */
  --border-color: rgba(232, 121, 43, 0.15);
  --border-subtle: rgba(232, 121, 43, 0.1);
  --border-strong: rgba(232, 121, 43, 0.2);
  --shadow-sm: 0 2px 8px rgba(232, 121, 43, 0.06);
  --shadow-md: 0 2px 12px rgba(232, 121, 43, 0.06);
  --shadow-hover: 0 4px 16px rgba(232, 121, 43, 0.12);
  --hover-bg: rgba(232, 121, 43, 0.06);
  --hover-bg-strong: rgba(232, 121, 43, 0.1);
  --focus-shadow: 0 0 0 3px rgba(232, 121, 43, 0.15);
  --scrollbar-thumb: rgba(232, 121, 43, 0.6);
  --scrollbar-hover: rgba(232, 121, 43, 0.75);
  --body-bg: linear-gradient(170deg, #FFF8F0 0%, #FFF0E6 40%, #FFEBD9 70%, #FFE4D0 100%);
  --logo-shadow: drop-shadow(0 2px 8px rgba(232, 121, 43, 0.15));
  --overlay-bg: rgba(255, 248, 240, 0.9);
  --modal-overlay: rgba(0, 0, 0, 0.5);
  --inset-shadow: inset 0 1px 3px rgba(92, 64, 51, 0.08);

  /* State colors */
  --proofread-bg: rgba(125, 195, 125, 0.2);
  --proofread-text: #3A7A3A;
  --proofread-border: #7DC37D;
  --openpr-bg: rgba(108, 180, 214, 0.2);
  --openpr-text: #2B7A9E;
  --warning-badge-text: #b36b00;
  --warning-badge-bg: #fff3e0;
  --warning-badge-border: #ffe0b2;
}

[data-theme="dark"] {
  --primary: #F0934A;
  --primary-dark: #E07830;
  --primary-light: #C07040;
  --secondary: #D4982A;
  --accent-pink: #D08090;
  --accent-green: #90A828;
  --bg: #1A1210;
  --bg-light: #201815;
  --surface: #2A201A;
  --surface-dark: #352A22;
  --card-bg: #241C16;
  --text: #E8D8C8;
  --text-muted: #A08878;
  --text-secondary: #9A8575;
  --success: #7CB342;
  --error: #E57373;
  --warning: #D4982A;

  --border-color: rgba(240, 147, 74, 0.12);
  --border-subtle: rgba(240, 147, 74, 0.08);
  --border-strong: rgba(240, 147, 74, 0.18);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 2px 12px rgba(0, 0, 0, 0.25);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.3);
  --hover-bg: rgba(240, 147, 74, 0.08);
  --hover-bg-strong: rgba(240, 147, 74, 0.12);
  --focus-shadow: 0 0 0 3px rgba(240, 147, 74, 0.2);
  --scrollbar-thumb: rgba(240, 147, 74, 0.6);
  --scrollbar-hover: rgba(240, 147, 74, 0.75);
  --body-bg: linear-gradient(170deg, #1A1210 0%, #1E1510 40%, #201812 70%, #221A14 100%);
  --logo-shadow: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
  --overlay-bg: rgba(26, 18, 16, 0.9);
  --modal-overlay: rgba(0, 0, 0, 0.7);
  --inset-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);

  --proofread-bg: rgba(125, 195, 125, 0.15);
  --proofread-text: #8BC68B;
  --proofread-border: #5A9A5A;
  --openpr-bg: rgba(108, 180, 214, 0.15);
  --openpr-text: #7CC4E6;
  --warning-badge-text: #D4A050;
  --warning-badge-bg: rgba(180, 120, 40, 0.15);
  --warning-badge-border: rgba(180, 120, 40, 0.25);
}

body {
  font-family: 'DF-FutoMaruGothic', 'Segoe UI', Tahoma, sans-serif;
  background: var(--body-bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
header {
  text-align: center;
  padding: 40px 20px 32px;
  margin-bottom: 8px;
}

header .logo {
  max-width: 420px;
  height: auto;
  margin-bottom: 8px;
  filter: var(--logo-shadow);
}

header h1 {
  font-size: 2rem;
  background: linear-gradient(135deg, #F5A623, var(--primary), var(--primary-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  letter-spacing: 0.3px;
}

#auth-status {
  margin-top: 20px;
}

.auth-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
}

.auth-info img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.auth-info span {
  color: var(--text-muted);
}

/* Theme Toggle */
.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.theme-toggle:hover {
  background: var(--primary);
  color: white;
  transform: scale(1.1);
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-block;
}

.btn.primary {
  background: linear-gradient(135deg, #F5A623, var(--primary), var(--primary-dark));
  color: white;
}

.btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(232, 121, 43, 0.35);
}

.btn.secondary {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn.secondary:hover {
  background: var(--surface);
  border-color: var(--primary-light);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn.small {
  padding: 6px 12px;
  font-size: 0.85rem;
}

/* Search Section */
.search-section {
  margin: 0 0 40px;
}

.search-box {
  display: flex;
  gap: 10px;
}

.search-box input {
  flex: 1;
  padding: 15px 20px;
  font-size: 1.1rem;
  font-family: 'HeiSeiMaruGothic', sans-serif;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  background: var(--card-bg);
  color: var(--text);
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-shadow);
}

.search-hint {
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}

/* Results Section */
#results-section {
  margin-bottom: 40px;
}

#results-section h2 {
  margin-bottom: 20px;
  color: var(--primary);
}

#results-list {
  display: grid;
  gap: 15px;
}

.result-item {
  background: var(--card-bg);
  padding: 20px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.result-item:hover {
  border-color: var(--primary-light);
  transform: translateX(4px);
  box-shadow: var(--shadow-hover);
}

.result-item .file-path {
  font-family: monospace;
  color: var(--primary);
  font-size: 1rem;
  margin-bottom: 8px;
}

.result-item .preview {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.result-item.expanded {
  border-color: var(--primary);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom: none;
  transform: none;
}

.result-item.expanded:hover {
  transform: none;
}

/* Inline File Viewer */
.inline-file-viewer {
  background: var(--surface);
  border-radius: 0 0 12px 12px;
  padding: 20px;
  border: 1px solid var(--primary);
  border-top: none;
  margin-bottom: 15px;
  animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.inline-file-viewer .file-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--surface);
  flex-wrap: wrap;
}

.inline-file-viewer .file-title {
  font-size: 1rem;
  color: var(--text-muted);
}

.inline-file-viewer .file-name {
  font-family: monospace;
  color: var(--primary);
  font-weight: 600;
}

.inline-file-viewer .file-actions {
  display: flex;
  gap: 10px;
}

.inline-file-viewer .dialogue-count {
  color: var(--text-muted);
  text-align: center;
  padding: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--surface);
  font-size: 0.9rem;
}

.inline-file-viewer .dialogue-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 10px;
}

/* File Viewer (legacy - kept for compatibility) */
#file-viewer {
  background: var(--bg-light);
  border-radius: 12px;
  padding: 25px;
  border: 1px solid var(--surface);
}

.file-header {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 25px;
  flex-wrap: wrap;
}

.file-header h2 {
  flex: 1;
  font-size: 1.2rem;
}

#file-name {
  font-family: monospace;
  color: var(--primary);
}

.dialogue-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
  max-height: 600px;
  overflow-y: auto;
  padding-right: 10px;
}

.dialogue-item {
  background: var(--card-bg);
  padding: 15px 20px;
  border-radius: 8px;
  position: relative;
  border-left: 3px solid transparent;
  transition: all 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.dialogue-item:hover {
  border-left-color: var(--primary);
}

.dialogue-item.highlight {
  border-left-color: var(--secondary);
  background: rgba(255, 184, 48, 0.1);
}

.dialogue-speaker {
  font-weight: 600;
  color: var(--primary);
  font-size: 0.9rem;
  margin-bottom: 5px;
}

.dialogue-speaker.protagonist {
  color: var(--accent-pink);
}

.dialogue-speaker.narration {
  color: var(--text-muted);
  font-style: italic;
}

.dialogue-text {
  color: var(--text);
  line-height: 1.7;
  white-space: pre-wrap;
}

.dialogue-actions {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  background: var(--card-bg);
  border-radius: 12px;
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.modal-content h2 {
  padding: 20px 25px;
  border-bottom: 1px solid var(--surface);
  color: var(--primary);
}

.modal-body {
  padding: 25px;
}

.field {
  margin-bottom: 20px;
}

.field label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-muted);
}

.text-box {
  width: 100%;
  padding: 15px;
  border-radius: 6px;
  border: 1px solid var(--surface);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.6;
  background: var(--surface);
  color: var(--text);
}

.text-box.readonly {
  background: var(--bg);
  white-space: pre-wrap;
}

.text-box.editable {
  resize: vertical;
  min-height: 100px;
}

.text-box.editable:focus {
  outline: none;
  border-color: var(--primary);
}

.field input[type="text"] {
  width: 100%;
  padding: 12px 15px;
  border-radius: 6px;
  border: 1px solid var(--surface);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.field input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
}

.modal-footer {
  padding: 20px 25px;
  border-top: 1px solid var(--surface);
  display: flex;
  gap: 15px;
  justify-content: flex-end;
}

/* Game-style Preview */
.game-preview {
  display: flex;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #f5d6c6 0%, #fce5d8 50%, #fff0e6 100%);
  border-radius: 8px;
  overflow: hidden;
}

.game-box {
  border-image-source: url('msg_window.png');
  border-image-slice: 143 120 89 381;
  border-image-width: 50px 50px 40px 125px;
  border-style: solid;
  padding: 37px 15px 16px 11px;
  font-family: 'HeiSeiMaruGothic', sans-serif;
  font-size: 11.5pt;
  width: fit-content;
  position: relative;
}

.game-speaker {
  position: absolute;
  font-family: 'HeiSeiMaruGothic', sans-serif;
  top: 17px;
  left: 20px;
  color: #000000b3;
  font-size: 11.5pt;
}

.game-contents {
  text-overflow: clip;
  white-space: nowrap;
  background-color: #FFFFFF;
  border-radius: 11px;
  padding-top: 0.2em;
  padding-bottom: 0.3em;
  padding-left: 1em;
  line-height: 1.4em;
  width: fit-content;
  padding-right: 1em;
  color: #000000b3;
  box-shadow: inset 0 0 10px #00000030;
  overflow: hidden;
}

.game-text {
  padding-left: 0.25em;
  padding-right: 0.25em;
  padding-bottom: 3px;
  width: 22.3em;
  overflow: hidden;
}

.game-line {
  border-bottom: 2px solid #0000003d;
  padding-top: 3px;
  min-height: 1.3em;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.preview-hint {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 10px;
}

/* Y files use larger font (35pt vs 31pt default) - ratio 1.129 */
.game-box.y-file {
  font-size: 13pt;
}

.game-box.y-file .game-speaker {
  font-size: 13pt;
}

/* Y files can show unlimited lines - allow overflow */
.game-box.y-file .game-contents {
  overflow: visible;
}

.game-box.y-file .game-text {
  overflow: visible;
}

.game-box.y-file .game-line {
  overflow: visible;
  text-overflow: clip;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--surface-dark);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay p {
  margin-top: 20px;
  color: var(--text);
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 15px 20px;
  border-radius: 8px;
  color: white;
  font-weight: 500;
  animation: slideIn 0.3s ease;
  max-width: 400px;
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--error);
}

.toast.warning {
  background: var(--warning);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Hidden utility */
.hidden {
  display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-hover);
}

/* Responsive */
@media (max-width: 768px) {
  header h1 {
    font-size: 1.8rem;
  }

  .search-box {
    flex-direction: column;
  }

  .file-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
