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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #333;
  background: #f4f6f8;
}

/* ========== Header ========== */
header {
  background: #1a73e8;
  color: white;
  padding: 1rem 1rem 1.25rem;
  text-align: center;
  position: relative;
}

.back-link {
  display: inline-block;
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  padding: 0.25rem 0;
  min-height: 44px;
  line-height: 44px;
}

.back-link:hover {
  color: #fff;
  text-decoration: underline;
}

header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.4;
}

.subtitle {
  font-size: 0.875rem;
  opacity: 0.9;
  margin-top: 0.35rem;
}

/* ========== Main ========== */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
}

/* ========== Ad Units ========== */
.ad-unit {
  margin: 1.25rem 0;
}

/* ========== Tool Section ========== */
.tool-section {
  background: white;
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.08);
}

/* ========== Toolbar ========== */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.toolbar-group {
  display: flex;
  gap: 0.5rem;
}

.btn-action {
  min-height: 44px;
  padding: 0 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  background: #e8f0fe;
  color: #1a73e8;
  border: 1px solid #c5d8fc;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn-action:hover {
  background: #d2e3fc;
}

.btn-action.btn-danger {
  background: #fce8e6;
  color: #c5221f;
  border-color: #f4c7c3;
}

.btn-action.btn-danger:hover {
  background: #f9d0ce;
}

.btn-copy {
  min-height: 56px;
  padding: 0 1.5rem;
  font-size: 1rem;
  font-weight: 700;
  background: #1a73e8;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-copy:hover {
  background: #1557b0;
}

.btn-copy.btn-copy-small {
  min-height: 44px;
  padding: 0 1rem;
  font-size: 0.875rem;
  border-radius: 6px;
}

/* ========== Table Wrapper ========== */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  margin-bottom: 1rem;
}

#editor-table {
  border-collapse: collapse;
  min-width: 100%;
  width: max-content;
  font-size: 0.9rem;
}

#editor-table th,
#editor-table td {
  border: 1px solid #d0d7de;
  padding: 0;
  position: relative;
}

#editor-table thead th {
  background: #f6f8fa;
}

/* Cell input */
.cell-input {
  display: block;
  width: 100%;
  min-width: 80px;
  min-height: 44px;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  font-family: inherit;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  line-height: 1.4;
  white-space: pre;
  overflow: hidden;
}

.cell-input:focus {
  background: #e8f0fe;
  outline: 2px solid #1a73e8;
  outline-offset: -2px;
}

/* Row number column */
.row-num {
  background: #f6f8fa;
  color: #888;
  font-size: 0.75rem;
  text-align: center;
  padding: 0 0.5rem;
  min-width: 36px;
  user-select: none;
  vertical-align: middle;
  border-right: 2px solid #d0d7de;
}

/* Header row indicator */
#editor-table thead .cell-input {
  font-weight: 700;
}

/* ========== Alignment Controls ========== */
.alignment-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.alignment-label {
  color: #555;
  white-space: nowrap;
  font-weight: 600;
}

#alignment-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.align-select {
  min-height: 44px;
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: white;
  cursor: pointer;
}

.align-select-label {
  font-size: 0.75rem;
  color: #666;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

/* ========== Markdown Preview ========== */
.preview-section {
  margin-top: 1rem;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.preview-header h2 {
  font-size: 1rem;
  color: #444;
}

#markdown-output {
  background: #f6f8fa;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: 0.85rem 1rem;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
  color: #333;
  min-height: 60px;
}

/* Copy success feedback */
.btn-copy.copied {
  background: #34a853;
}

/* ========== Import Section ========== */
.import-section {
  margin-top: 1.5rem;
  border-top: 1px solid #eee;
  padding-top: 1.25rem;
}

.import-section h2 {
  font-size: 1rem;
  color: #444;
  margin-bottom: 0.6rem;
}

#markdown-input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  font-size: 0.875rem;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  border: 1px solid #ccc;
  border-radius: 6px;
  resize: vertical;
  line-height: 1.5;
  color: #333;
}

#markdown-input:focus {
  outline: 2px solid #1a73e8;
  border-color: #1a73e8;
}

.btn-import {
  display: block;
  width: 100%;
  margin-top: 0.75rem;
  min-height: 44px;
  padding: 0 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  background: #34a853;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-import:hover {
  background: #2d8e47;
}

/* ========== Howto Section ========== */
.howto-section {
  margin-top: 1.5rem;
  background: white;
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.08);
}

.howto-section h2 {
  font-size: 1.1rem;
  color: #1a73e8;
  margin-bottom: 0.75rem;
  margin-top: 1.25rem;
  padding-bottom: 0.3rem;
  border-bottom: 2px solid #e8f0fe;
}

.howto-section h2:first-child {
  margin-top: 0;
}

.howto-section ol {
  padding-left: 1.4rem;
  color: #444;
  font-size: 0.95rem;
}

.howto-section li {
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

.howto-section p {
  font-size: 0.95rem;
  color: #555;
  line-height: 1.75;
}

.howto-section code {
  background: #f6f8fa;
  border: 1px solid #e1e4e8;
  border-radius: 3px;
  padding: 0.1em 0.4em;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.85em;
}

/* ========== Footer ========== */
footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.85rem;
  color: #888;
}

footer a {
  color: #666;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

footer p + p {
  margin-top: 0.4rem;
}

/* ========== Responsive ========== */
@media (min-width: 640px) {
  header h1 {
    font-size: 1.5rem;
  }

  main {
    padding: 1.5rem 2rem;
  }

  .tool-section {
    padding: 1.75rem;
  }

  .btn-import {
    width: auto;
    min-width: 200px;
  }
}

@media (min-width: 960px) {
  header h1 {
    font-size: 1.75rem;
  }
}
