:root {
  --bg-main: #161b22;
  --bg-panel: #202734;
  --bg-input: #11161d;
  --bg-accent: #2f3a52;
  --text-main: #e5edf8;
  --text-muted: #9fb0c8;
  --line: #33405a;
  --primary: #47a2ff;
  --danger: #ff6b6b;
  --chip: #2a3449;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  color: var(--text-main);
  background: radial-gradient(circle at 20% 0%, #1b2435 0%, var(--bg-main) 55%);
  font-family: "Segoe UI", "Noto Sans KR", sans-serif;
}

body {
  display: flex;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

body.modal-open {
  overflow: hidden;
}

.sidebar {
  width: 320px;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #20283a 0%, #1c2333 100%);
  border-right: 1px solid var(--line);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar-header h1 {
  margin: 0;
  font-size: 1.15rem;
}

.sidebar-header p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.panel {
  background: rgba(17, 22, 29, 0.6);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.hint {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.input,
.textarea,
select.input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--bg-input);
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input:focus,
.textarea:focus,
select.input:focus,
.paste-zone:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(71, 162, 255, 0.2);
}

.textarea {
  resize: vertical;
}

.game-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
}

.list-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #1a2230;
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  cursor: pointer;
  text-align: left;
}

.list-item-top {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.list-item-main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.list-item-icon-wrap {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #101620;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}

.list-item-icon {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.list-item-icon-fallback {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #4f628a;
}

.list-item:hover {
  border-color: #4f628a;
}

.list-item.active {
  border-color: var(--primary);
  background: #1f2d46;
}

.list-item-title {
  font-size: 0.95rem;
  font-weight: 600;
  width: 100%;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.list-item-meta {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.empty-message {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 12px;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.88rem;
}

.button-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 20px;
}

.content-header {
  margin-bottom: 16px;
}

.content-header h2 {
  margin: 0;
}

.status-text {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.status-text.error {
  color: #ff8d8d;
}

.status-text.success {
  color: #89e0a8;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
}

.field {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: rgba(24, 31, 44, 0.55);
}

.inline-field {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-field .input {
  flex: 1;
}

.inline-field .btn {
  white-space: nowrap;
}

.field.full,
.icon-preview-wrap.full,
.actions.full {
  grid-column: 1 / -1;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
}

.screenshot-upload-grid {
  margin-top: 10px;
}

.upload-card {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px;
  background: rgba(12, 16, 22, 0.4);
}

.paste-zone {
  min-height: 60px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: text;
  outline: none;
}

.platform-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.platform-option-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(12, 16, 22, 0.42);
}

.platform-option-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

.platform-option-label input {
  accent-color: var(--primary);
}

.btn-small {
  padding: 6px 8px;
  font-size: 0.8rem;
}

.icon-preview-wrap {
  border: 1px dashed var(--line);
  border-radius: 10px;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 16, 22, 0.5);
}

.icon-preview {
  width: 84px;
  height: 84px;
  border-radius: 14px;
  border: 1px solid var(--line);
  object-fit: cover;
  background: #0f131a;
}

.screenshot-preview-list {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.screenshot-preview-empty {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.screenshot-preview-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 16, 22, 0.42);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.screenshot-preview-link {
  border-radius: 6px;
  overflow: hidden;
  display: block;
  line-height: 0;
}

.screenshot-preview-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #0f131a;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  background: #1a2230;
  font-size: 0.92rem;
}

.btn:hover {
  border-color: #4f628a;
}

.btn-primary {
  background: var(--bg-accent);
  border-color: #4f6ea5;
}

.btn-secondary {
  background: #273145;
}

.btn-danger {
  background: rgba(255, 107, 107, 0.16);
  border-color: rgba(255, 107, 107, 0.5);
}

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

.actions {
  display: flex;
  gap: 10px;
}

.crop-modal {
  position: fixed;
  inset: 0;
  padding: 18px;
  background: rgba(5, 9, 14, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1300;
}

.crop-modal[hidden] {
  display: none;
}

.crop-dialog {
  width: min(760px, 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: linear-gradient(180deg, #1f2738 0%, #171d2b 100%);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.crop-title {
  margin: 0;
  font-size: 1.04rem;
}

.crop-description {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.crop-canvas-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #0d121a;
}

.crop-canvas {
  width: 100%;
  height: min(58vh, 420px);
  display: block;
  cursor: grab;
  touch-action: none;
}

.crop-canvas.dragging {
  cursor: grabbing;
}

.crop-controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}

.crop-zoom-label {
  margin: 0;
}

.crop-zoom-range {
  width: 100%;
}

.crop-zoom-value {
  min-width: 50px;
  text-align: right;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.crop-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.hero-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  gap: 14px;
  background: rgba(24, 31, 44, 0.6);
}

.hero-icon {
  width: 88px;
  height: 88px;
  border-radius: 14px;
  border: 1px solid var(--line);
  object-fit: cover;
  background: #0f131a;
  flex-shrink: 0;
}

.hero-copy h3 {
  margin: 2px 0 8px;
}

.hero-copy p {
  margin: 0 0 8px;
  color: var(--text-muted);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid #46567a;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.78rem;
  background: var(--chip);
  color: #d4deef;
}

.chip-empty {
  border-style: dashed;
  color: var(--text-muted);
}

body[data-page="read"] .content {
  --read-section-space: 40px;
  /*기본 24px, 구분선 위/아래 간격*/
  --read-card-gap: 20px;
  /*기본 20px, 카드 사이 간격*/
  --read-note-gap: 20px;
  /*기본 20px, 메모 카드 위/아래 간격*/
  padding: 24px 28px 40px;
}

body[data-page="read"] .content>* {
  max-width: 1100px;
  margin-left: auto;
  margin-right: auto;
}

body[data-page="read"] .hero-card {
  margin-top: 4px;
  padding: 18px;
  gap: 16px;
}

body[data-page="read"] .read-section-divider {
  height: 1px;
  margin: var(--read-section-space) auto;
  background: linear-gradient(90deg, transparent 0%, #4b5d81 16%, #4b5d81 84%, transparent 100%);
}

body[data-page="read"] .read-section-divider-mid {
  margin: var(--read-section-space) auto;
}

.read-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
}

body[data-page="read"] .read-grid {
  margin-top: 0;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: var(--read-card-gap);
}

.study-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
}

body[data-page="read"] .study-grid {
  margin-top: 0;
  grid-template-columns: minmax(320px, 1.2fr) minmax(260px, 1fr);
  grid-template-areas:
    "features pros"
    "features cons";
  gap: var(--read-card-gap);
}

body[data-page="read"] .study-card-features {
  grid-area: features;
}

body[data-page="read"] .study-card-pros {
  grid-area: pros;
}

body[data-page="read"] .study-card-cons {
  grid-area: cons;
}

.read-card,
.read-note-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: rgba(24, 31, 44, 0.5);
}

body[data-page="read"] .read-card,
body[data-page="read"] .read-note-card {
  border-radius: 12px;
  padding: 16px;
}

.read-card h4,
.read-note-card h4 {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

body[data-page="read"] .read-card h4,
body[data-page="read"] .read-note-card h4 {
  margin-bottom: 10px;
}

.read-card p,
.read-note-card p,
.read-card .markdown-content,
.read-note-card .markdown-content {
  margin: 0;
  line-height: 1.4;
}

body[data-page="read"] .read-card p,
body[data-page="read"] .read-note-card p,
body[data-page="read"] .read-card .markdown-content,
body[data-page="read"] .read-note-card .markdown-content {
  line-height: 1.55;
}

.read-card .markdown-content > :first-child,
.read-note-card .markdown-content > :first-child {
  margin-top: 0;
}

.read-card .markdown-content > :last-child,
.read-note-card .markdown-content > :last-child {
  margin-bottom: 0;
}

.read-card .markdown-content p,
.read-note-card .markdown-content p {
  margin: 0 0 10px;
}

.read-card .markdown-content p,
.read-note-card .markdown-content p,
.read-card .markdown-content li,
.read-note-card .markdown-content li,
.read-card .markdown-content blockquote,
.read-note-card .markdown-content blockquote {
  white-space: pre-wrap;
  tab-size: 2;
}

.read-card .markdown-content ul,
.read-card .markdown-content ol,
.read-note-card .markdown-content ul,
.read-note-card .markdown-content ol {
  margin: 0 0 10px;
  padding-left: 20px;
}

.read-card .markdown-content li + li,
.read-note-card .markdown-content li + li {
  margin-top: 4px;
}

.read-card .markdown-content code,
.read-note-card .markdown-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  background: rgba(64, 79, 109, 0.36);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 5px;
}

.read-card .markdown-content pre,
.read-note-card .markdown-content pre {
  margin: 0 0 10px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #121824;
  overflow-x: auto;
}

.read-card .markdown-content pre code,
.read-note-card .markdown-content pre code {
  border: 0;
  background: transparent;
  padding: 0;
}

.read-card .markdown-content blockquote,
.read-note-card .markdown-content blockquote {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-left: 3px solid #4f6ea5;
  background: rgba(31, 45, 70, 0.45);
  color: var(--text-muted);
}

.author-info .markdown-content {
  flex: 1;
}

.screenshot-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}

.screenshot-gallery-empty {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 12px;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.88rem;
}

.screenshot-thumb-button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  overflow: hidden;
  background: #111722;
  cursor: pointer;
  line-height: 0;
}

.screenshot-thumb-button:hover {
  border-color: #4f628a;
}

.screenshot-thumb-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #0f131a;
}

.image-viewer-modal {
  position: fixed;
  inset: 0;
  padding: 20px;
  background: rgba(4, 9, 14, 0.86);
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-viewer-modal[hidden] {
  display: none;
}

.image-viewer-dialog {
  position: relative;
  width: min(92vw, 1280px);
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-viewer-image {
  max-width: 100%;
  max-height: 86vh;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f131a;
}

.image-viewer-close-btn {
  position: absolute;
  top: -42px;
  right: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1a2230;
  color: var(--text-main);
  padding: 6px 10px;
  cursor: pointer;
}

.author-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.author-avatar,
.author-avatar-placeholder {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--line);
  flex-shrink: 0;
}

.author-avatar {
  object-fit: cover;
  background: #0f131a;
}

.author-avatar-placeholder {
  background: #2a3449;
}

.read-note-card {
  margin-top: 10px;
}

body[data-page="read"] .read-note-card {
  margin-top: var(--read-note-gap);
}

body[data-page="read"] .study-grid .read-note-card {
  margin-top: 0;
}

body[data-page="read"] .study-grid+.read-note-card {
  margin-top: var(--read-note-gap);
}

.login-layout {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  background: rgba(24, 31, 44, 0.6);
}

.login-card h2 {
  margin: 0 0 10px;
}

@media (max-width: 1080px) {
  body {
    flex-direction: column;
    height: auto;
    overflow: auto;
  }

  .sidebar {
    width: 100%;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 44vh;
  }

  .content {
    height: auto;
    overflow: visible;
    padding: 14px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .upload-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column;
  }

  .inline-field {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-field .btn {
    width: 100%;
  }

  .crop-actions {
    flex-direction: column;
  }

  .crop-actions .btn {
    width: 100%;
  }

  .read-grid {
    grid-template-columns: 1fr 1fr;
  }

  .study-grid {
    grid-template-columns: 1fr;
  }

  body[data-page="read"] .read-grid,
  body[data-page="read"] .study-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  body[data-page="read"] .study-grid {
    grid-template-areas:
      "features"
      "pros"
      "cons";
  }

  .login-layout {
    align-items: flex-start;
    justify-content: stretch;
  }

  .login-card {
    width: 100%;
  }
}

@media (max-width: 680px) {
  .read-grid {
    grid-template-columns: 1fr;
  }

  body[data-page="read"] .content {
    padding: 14px;
  }

  .hero-card {
    flex-direction: column;
  }

  .crop-modal {
    padding: 10px;
  }

  .crop-dialog {
    padding: 12px;
  }

  .crop-canvas {
    height: min(52vh, 320px);
  }

  .image-viewer-modal {
    padding: 12px;
  }

  .image-viewer-close-btn {
    top: -40px;
    right: 0;
  }
}
